Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

4/21/22, 9:25 AM Midterm-Machine Learning 20BCE2251 - Jupyter Notebook

Name-Tanmay Mehrotra

Regno-20BCE2251

Slot-L19+20
In [50]: import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score,confusion_matrix,precision_score
p=pd.read_csv("bank-additional_full.csv")
d=pd.DataFrame(p)
p.head(10)

Out[50]:
age job marital education default balance housing loan contact day month d

0 58 management married tertiary no 2143 yes no unknown 5 may

1 44 technician single secondary no 29 yes no unknown 5 may

2 33 entrepreneur married secondary no 2 yes yes unknown 5 may

3 47 blue-collar married unknown no 1506 yes no unknown 5 may

4 33 unknown single unknown no 1 no no unknown 5 may

5 35 management married tertiary no 231 yes no unknown 5 may

6 28 management single tertiary no 447 yes yes unknown 5 may

7 42 entrepreneur divorced tertiary yes 2 yes no unknown 5 may

8 58 retired married primary no 121 yes no unknown 5 may

9 43 technician single secondary no 593 yes no unknown 5 may

localhost:8888/notebooks/Midterm-Machine Learning 20BCE2251.ipynb 1/4


4/21/22, 9:25 AM Midterm-Machine Learning 20BCE2251 - Jupyter Notebook

In [51]: x=d.iloc[:,:-1].values
y=d.iloc[:,-1]
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.4,random_state=42)
y

Out[51]: 0 no

1 no

2 no

3 no

4 no

...

45206 yes

45207 yes

45208 yes

45209 no

45210 no

Name: Target, Length: 45211, dtype: object

localhost:8888/notebooks/Midterm-Machine Learning 20BCE2251.ipynb 2/4


4/21/22, 9:25 AM Midterm-Machine Learning 20BCE2251 - Jupyter Notebook

In [60]: c=MLPClassifier(hidden_layer_sizes=(200,100,50,20),random_state=5,verbose=True,le
g=c.fit(x_train,y_train)
g.score(x_test,y_test)
y_pred=g.predict(x_test)
accuracy_score(y_pred,y_test)
confusion_matrix(y_pred,y_test)
precision_score(y_pred,y_test)

---------------------------------------------------------------------------

ValueError Traceback (most recent call last)

<ipython-input-60-dac92038c889> in <module>

1 c=MLPClassifier(hidden_layer_sizes=(200,100,50,20),random_state=5,verbo
se=True,learning_rate=10)

----> 2 g=c.fit(x_train,y_train)

3 g.score(x_test,y_test)

4 y_pred=g.predict(x_test)

5 accuracy_score(y_pred,y_test)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_p
erceptron.py in fit(self, X, y)

1025 self : returns a trained MLP model.

1026 """

-> 1027 return self._fit(X, y, incremental=(self.warm_start and

1028 hasattr(self, "classes_")))

1029

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_p
erceptron.py in _fit(self, X, y, incremental)

319

320 # Validate input parameters.

--> 321 self._validate_hyperparameters()

322 if np.any(np.array(hidden_layer_sizes) <= 0):

323 raise ValueError("hidden_layer_sizes must be > 0, got %s."


%

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_p
erceptron.py in _validate_hyperparameters(self)

421 % (self.activation, list(sorted(ACTIVATION


S))))

422 if self.learning_rate not in ["constant", "invscaling", "adapti


ve"]:

--> 423 raise ValueError("learning rate %s is not supported. " %

424 self.learning_rate)

425 supported_solvers = _STOCHASTIC_SOLVERS + ["lbfgs"]

ValueError: learning rate 10 is not supported.

In [ ]: ​

localhost:8888/notebooks/Midterm-Machine Learning 20BCE2251.ipynb 3/4


4/21/22, 9:25 AM Midterm-Machine Learning 20BCE2251 - Jupyter Notebook

localhost:8888/notebooks/Midterm-Machine Learning 20BCE2251.ipynb 4/4

You might also like