Reputation: 135
I am currently following along with a Machine Learning Full Course sponsored by Simplilearn to get a better understanding of regression, and am running into this error:
TypeError: init() got an unexpected keyword argument 'categorical_features' From this code:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
%matplotlib inline
companies = pd.read_csv('Companies_1000.csv')
X = companies.iloc[:, :-1].values
X = companies.iloc[:, :4].values
companies.head()
cmap = sns.cm.rocket_r
sns.heatmap(companies.corr(), cmap = cmap)
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder = LabelEncoder()
X[:, 3] = labelencoder.fit_transform(X[:, 3])
onehotencoder = OneHotEncoder(categorical_features = [3])
X = onehotencoder.fit_transform(X).toarray()
print(X)
This is the csv file: https://raw.githubusercontent.com/boosuro/profit_estimation_of_companies/master/1000_Companies.csv
The video does not get the same error as me, and I have assumed that it is outdated, however after crawling through the sklearn docs, I have come up empty-handed for a solution. I am using python 3. If you want to check out exactly the info and code that's happening in the video, here it is:
https://www.youtube.com/watch?v=9f-GarcDY58
My error appears around the 47:25 mark. Thank you for checking this out, and thanks for your answers.
Upvotes: 0
Views: 141
Reputation: 1746
The error is due to the following line
onehotencoder = OneHotEncoder(categorical_features = [3])
There is no parameter named "categorical_features" . Instead there is "categories" where you can pass a list of categories. By default "categories" is set to "auto" which means it will automatically determine categories from the training data.
So you need not to pass anything in the OneHotEncoder() function, just leave it like this.
Change the line as below
onehotencoder = OneHotEncoder()
Upvotes: 1