MLPClassifier和MLPRegression
class?sklearn.neural_network.MLPClassifier(hidden_layer_sizes=(100,),?activation='relu',?*,?solver='adam',?alpha=0.0001,?batch_size='auto',?learning_rate='constant',?learning_rate_init=0.001,?power_t=0.5,?max_iter=200,?shuffle=True,?random_state=None,?tol=0.0001,?verbose=False,?warm_start=False,?momentum=0.9,?nesterovs_momentum=True,?early_stopping=False,?validation_fraction=0.1,?beta_1=0.9,?beta_2=0.999,?epsilon=1e-08,?n_iter_no_change=10,?max_fun=15000)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn.neural_network import MLPRegressor
from sklearn.datasets import load_boston, load_breast_cancer, load_wine, load_iris
import warnings
warnings.simplefilter("ignore")
bonston = load_boston()
cancer = load_breast_cancer()
wine = load_wine()
iris = load_iris()
class?sklearn.neural_network.MLPRegressor(hidden_layer_sizes=(100,),?activation='relu',?*,?solver='adam',?alpha=0.0001,?batch_size='auto',?learning_rate='constant',?learning_rate_init=0.001,?power_t=0.5,?max_iter=200,?shuffle=True,?random_state=None,?tol=0.0001,?verbose=False,?warm_start=False,?momentum=0.9,?nesterovs_momentum=True,?early_stopping=False,?validation_fraction=0.1,?beta_1=0.9,?beta_2=0.999,?epsilon=1e-08,?n_iter_no_change=10,?max_fun=15000)
data_train, data_test, target_train, target_test = train_test_split(bonston.data, bonston.target, test_size = 0.2, random_state = 0)
mlpr = MLPRegressor(random_state = 0)
mlpr.fit(data_train, target_train)
train_score = mlpr.score(data_train, target_train)
print('train score:', train_score)
test_score = mlpr.score(data_test, target_test)
print('test score:', test_score)
回归
二分类
多分类
data_train, data_test, target_train, target_test = train_test_split(cancer.data, cancer.target, test_size = 0.2, random_state = 0)
mlpc = MLPClassifier(random_state = 0)
mlpc.fit(data_train, target_train)
train_score = mlpc.score(data_train, target_train)
print('train score:', train_score)
test_score = mlpc.score(data_test, target_test)
print('test score:', test_score)
data_train, data_test, target_train, target_test = train_test_split(wine.data, wine.target, test_size = 0.2, random_state = 0)
mlpc = MLPClassifier(random_state = 0)
mlpc.fit(data_train, target_train)
train_score = mlpc.score(data_train, target_train)
print('train score:', train_score)
test_score = mlpc.score(data_test, target_test)
print('test score:', test_score)
|