Example #1
0
imputer.fit(housing_num)


# In[51]:


imputer.statistics_


# Transform the training set:

# In[52]:


X = imputer.transform(housing_num)
X


# In[53]:


housing_tr = pd.DataFrame(X, columns=housing_num.columns)
housing_tr.info()


# Now let's preprocess the categorical input feature, `ocean_proximity`:

# In[54]:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# importing the dataset
dataset = pd.read_csv("Data.csv")
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values

# Taking care of missing data: Not needed in template
from sklearn.preprocessing import SimpleImputer
missingvalues = SimpleImputer(missing_values=np.nan,
                              strategy="mean",
                              verbose=0)
missingvalues = missingvalues.fit(X[:, 1:])
X[:, 1:] = missingvalues.transform(X[:, 1:])

# Encoding Categorical Data: Not needed in template
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer

ct = ColumnTransformer([('encoder', OneHotEncoder(), [0])],
                       remainder='passthrough')
X = np.array(ct.fit_transform(X), dtype=np.float)

from sklearn.preprocessing import LabelEncoder
y = LabelEncoder().fit_transform(y)

# Splitting data
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,
# Data Preprocessing

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values

# Taking care of missing data
from sklearn.preprocessing import SimpleImputer
imputer = SimpleImputer(missing_values='NaN', strategy='mean', axis=0)
imputer = imputer.fit(X[:, 1:3])
X[:, 1:3] = imputer.transform(X[:, 1:3])