Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to convert this onehotencoder so it can run on scikitlearn 0.22.1 import numpy as np import pandas as pd from sklearn.metrics import confusion_matrix, accuracy_score

How to convert this onehotencoder so it can run on scikitlearn 0.22.1

import numpy as np
import pandas as pd
from sklearn.metrics import confusion_matrix, accuracy_score
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import r2_score

dataset = pd.read_csv(‘heart.csv’)
X = dataset.iloc[:,:-1].values
y = dataset.iloc[:,-1].values

from sklearn.preprocessing import OneHotEncoder #cp oneHotEncoder = OneHotEncoder(categorical_features=[2], n_values='auto') oneHotEncoder.fit(X) X = oneHotEncoder.transform(X).toarray() X = X[:, 1:] #restecg oneHotEncoder = OneHotEncoder(categorical_features=[8], n_values='auto') oneHotEncoder.fit(X) X = oneHotEncoder.transform(X).toarray() X = X[:, 1:] #slope oneHotEncoder = OneHotEncoder(categorical_features=[13], n_values='auto') oneHotEncoder.fit(X) X = oneHotEncoder.transform(X).toarray() X = X[:, 1:] #ca oneHotEncoder = OneHotEncoder(categorical_features=[15], n_values='auto') oneHotEncoder.fit(X) X = oneHotEncoder.transform(X).toarray() X = X[:, 1:] #thal oneHotEncoder = OneHotEncoder(categorical_features=[19], n_values='auto') oneHotEncoder.fit(X) X = oneHotEncoder.transform(X).toarray() X = X[:, 1:] from sklearn.preprocessing import StandardScaler scalerX = StandardScaler() X = scalerX.fit_transform(X)

because the new version of sklearn onehotencoder doesnt have categorical_features attribute please help

Step by Step Solution

3.44 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

In the sklearn 022 the categoricalfeatures were deprecated So ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Chemical Principles

Authors: Steven S. Zumdahl, Donald J. DeCoste

7th edition

9781133109235, 1111580650, 978-1111580650

More Books

Students also viewed these Programming questions

Question

5.1 Describe how culture influences self-concepts.

Answered: 1 week ago