import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.neural_network import MLPClassifier
namesE=['Country','SA','FE','GG','EC','UD','HF','SL','PS','HR','DP','RD','EX','TR','ND','AD']
data = pd.read_csv('datasets/problemE/Select30CountryEKind.csv',names=namesE)
del data['Country']
X = np.array(data.values.tolist())
Y = np.array([1,2,1,3,1,1,1,1,2,3,3,2,3,1,1,2,1,2,3,2,2,1,1,2,1,1,1,2,2,2])
scaler = StandardScaler()
StandardScaler(copy=True, with_mean=True, with_std=True)
scaler.fit(X)
X = scaler.transform(X)
mlp = MLPClassifier(hidden_layer_sizes=(15,15,15),max_iter=5000)
mlp.fit(X,Y)
DataOri = np.array([[4.5,4.9,4.8,5.4,2.9,2.0,3.7,2.7,2.0,4.3,5.5,2.5,0,0,0]])
for i in range (8,11):
for j in range(4,11):
for k in range(9,11):
tarr = [4.5,4.9,4.8,5.4,2.9,2.0,3.7,2.7,2.0,4.3,5.5,2.5]
tarr.append(i)
tarr.append(j)
tarr.append(k)
narr=np.array(tarr)
DataOri = np.row_stack((DataOri, narr))
DataOri
indoXTest = scaler.transform(DataOri)
#indoXTest = scaler.transform(indoDataOri)
predictions = mlp.predict(indoXTest)
predictions = mlp.predict(indoXTest)
plt.figure(figsize=(8,8))
plt.title('Predicting Tipping Point of Italy using MLP method',fontsize='large',fontweight='bold')
plot(predictions)
Dataflo = np.array([[4.5,4.9,4.8,5.4,2.9,2.0,3.7,2.7,2.0,4.3,5.5,2.5,0,0,0]])
TR=8.559
ND=4
AD=9
while TR <= 10:
ND=4
while ND <=10:
AD=9
while AD <=10:
tarr = [4.5,4.9,4.8,5.4,2.9,2.0,3.7,2.7,2.0,4.3,5.5,2.5]
tarr.append(TR)
tarr.append(ND)
tarr.append(AD)
narr=np.array(tarr)
Dataflo = np.row_stack((Dataflo, narr))
AD = AD+0.1
ND = ND+0.1
TR=TR+0.1
Dataflo
floXTest = scaler.transform(Dataflo)
predictionsFlo = mlp.predict(floXTest)
predictionsFlo = mlp.predict(floXTest)
plt.figure(figsize=(8,8))
plt.title('Predicting Tipping Point of Italy using MLP method',fontsize='large',fontweight='bold')
plot(predictionsFlo)
网友评论