import numpy as np
from sklearn.preprocessing import MinMaxScaler
data = np.random.randint(0,100,(10,2))
data
array([[90, 77], [82, 35], [ 9, 71], [20, 64], [39, 42], [74, 45], [35, 37], [92, 64], [49, 0], [11, 63]])
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x=data[:,0]
y=data[:,1]
plt.figure(figsize=(8,6))
plt.plot(x,y,'r')
plt.xlabel('x')
plt.ylabel('y')
plt.title(r"Plot of y")
plt.show()
scaler_model=MinMaxScaler()
scaler_model.fit(data)
MinMaxScaler(copy=True, feature_range=(0, 1))
result=scaler_model.transform(data)
#scaler_model_fit_transform(data) Alternative to the above 2 steps
result
array([[0.97590361, 1. ], [0.87951807, 0.45454545], [0. , 0.92207792], [0.13253012, 0.83116883], [0.36144578, 0.54545455], [0.78313253, 0.58441558], [0.31325301, 0.48051948], [1. , 0.83116883], [0.48192771, 0. ], [0.02409639, 0.81818182]])
x=result[:,0]
y=result[:,1]
plt.figure(figsize=(8,6))
plt.plot(x,y,'r')
plt.xlabel('x')
plt.ylabel('y')
plt.title(r"Plot of y")
plt.show()
data
array([[90, 77], [82, 35], [ 9, 71], [20, 64], [39, 42], [74, 45], [35, 37], [92, 64], [49, 0], [11, 63]])
import pandas as pd
data= pd.DataFrame(data=np.random.randint(0,101,(50,4)),columns=['f1','f2','f3','label'])
data.head()
f1 | f2 | f3 | label | |
---|---|---|---|---|
0 | 59 | 38 | 9 | 67 |
1 | 33 | 33 | 57 | 42 |
2 | 0 | 73 | 68 | 56 |
3 | 75 | 27 | 41 | 86 |
4 | 33 | 20 | 0 | 100 |
x=data[['f1','f2','f3']]
y=data['label']
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(x,y,test_size=0.3,random_state=101)
X_train.shape
(35, 3)
X_test.shape
(15, 3)
Y_train.shape
(35,)
Y_test.shape
(15,)