In [1]:
import numpy as np
In [2]:
# Importing MinMaxScaler
from sklearn.preprocessing import MinMaxScaler
In [3]:
data = np.random.randint(0,100,(10,2))
In [4]:
data
Out[4]:
In [5]:
scaler_model = MinMaxScaler()
In [6]:
scaler_model.fit(data)
Out[6]:
In [7]:
scaler_model.transform(data)
Out[7]:
In [8]:
# In one step
result = scaler_model.fit_transform(data)
In [9]:
result
Out[9]:
In [10]:
import pandas as pd
In [11]:
data = pd.DataFrame(data = np.random.randint(0, 101, size = (50,4)),
columns = ['f1','f2','f3','label'])
In [12]:
data.head()
Out[12]:
In [13]:
x = data[['f1', 'f2', 'f3']] # Alternatively x = data.drop('label',axis=1)
y = data['label']
In [14]:
# Train-test split
from sklearn.model_selection import train_test_split
In [15]:
# Splitting the dataset into train and test dataset with given test size and random state (data will be shuffled)
X_train, X_test, y_train, y_test = train_test_split(x, y,
test_size = 0.3,
random_state = 101)
In [16]:
X_train.shape
Out[16]:
In [17]:
X_train[0:5]
Out[17]:
In [18]:
X_test.shape
Out[18]:
In [19]:
y_train.shape
Out[19]:
In [20]:
y_test.shape
Out[20]: