Pandas Session 8 Code For Video Click Fahad Hussain CS
Hi, Welcome to Fahad Hussain CS blog, do not forget to subscribe and follow the blog and YouTube channel Fahad Hussain CS
Code:
import numpy as np
import pandas as pd
from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
print('User uploaded file "{name}" with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
data = pd.read_csv('DataSet.csv')
data.head()
X = data.iloc[:,:-1].values
y = data.iloc[:,3].values
X
y
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values = np.nan, strategy = 'mean')
imputer = imputer.fit(X[:,1:3])
X[:,1:3] = imputer.transform(X[:,1:3])
X
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from sklearn.compose import ColumnTransformer
ct = ColumnTransformer([("Developer",OneHotEncoder(),[0])], remainder = 'passthrough')
ct = ct.fit_transform(X)
labelencoder = LabelEncoder()
X[:,0] = labelencoder.fit_transform(X[:,0])
X
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.2, random_state = 0)
X_train
X_test
y_train
y_test
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_test = sc.fit_transform(X_test)
X_train = sc.fit_transform(X_train)
X_test
X_train
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.