简体   繁体   English

如何做出新的预测

[英]How to make a new prediction

Let me explain, i'm working with an Artificial Neural Network. 让我解释一下,我正在使用人工神经网络。 This model has 15 variables, 14 independents and one dependent. 该模型具有15个变量,14个独立变量和一个相关变量。 In the independent variables i've 3 categorical variables (day of week, month, direction(north,south, etc...)) . 在自变量中,我有3个类别变量(day of week, month, direction(north,south, etc...)) I already enconde them (monday = 1, tuesday = 2, and so...), also i hot encode them (monday = [1,0,0,0], tuesday = [0,1,0,0]) . 我已经对它们进行编码(monday = 1, tuesday = 2, and so...),我也对它们进行了热编码(monday = [1,0,0,0], tuesday = [0,1,0,0])

My question is, How can i make a prediction with new values, somethig like this. 我的问题是,我该如何用新的值进行预测,就像这样。

X=['Monday','January','South']

Here is the code 这是代码

# Classification template

# Importing the libraries
import numpy as np
import pandas as pd

# Importing the dataset

dataset = pd.read_csv('clean.csv')

X = dataset.iloc[:, [4,5,6,9,12,15,16]].values
y = dataset.iloc[:, 14].values

#Encoding categorical Data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelenconder_X = LabelEncoder()
X[:,1] = labelenconder_X.fit_transform(X[:,1])

labelenconder_X_2 = LabelEncoder()
X[:,2] = labelenconder_X_2.fit_transform(X[:,2])

labelenconder_X_7 = LabelEncoder()
X[:,4] = labelenconder_X_7.fit_transform(X[:,4])

labelenconder_X_9 = LabelEncoder()
X[:,5] = labelenconder_X_9.fit_transform(X[:,5])

labelenconder_X_10 = LabelEncoder()
X[:,6] = labelenconder_X_10.fit_transform(X[:,6])

onehotencoder = OneHotEncoder(categorical_features=[1,2,4,5,6])

X = onehotencoder.fit_transform(X).toarray()

X = X[:, 1:]



# Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)

# Feature Scaling
#from sklearn.preprocessing import StandardScaler
#sc = StandardScaler()
#X_train = sc.fit_transform(X_train)
#X_test = sc.transform(X_test)

# Fitting classifier to the Training set
# Create your classifier here
import keras
from keras.models import Sequential
from keras.layers import Dense


classifier = Sequential()

                    #INPUT LAYER AND HIDDEN LAYER
classifier.add(Dense(units = 5, kernel_initializer = 'uniform', activation = 'relu', input_dim =9))

                    #ADDING SECOND HIDDEN LAYER
classifier.add(Dense(units = 5, kernel_initializer = 'uniform', activation =  'relu'))

                    #adding output node 
classifier.add(Dense(units= 1, kernel_initializer = 'uniform', activation = 'sigmoid'))

                    #Applygin Stochasting Gradient Descent

classifier.compile(optimizer='adam', loss = 'binary_crossentropy', metrics=['accuracy'])

classifier.fit(X_train, y_train, batch_size =28, epochs = 100)


classifier.save('ANN2.h5')
model = keras.models.load_model('ANN2.h5')
y_predict = model.predict(X_test)
y_predict = (y_predict > 0.40)

If you want to encode all days of the week for a prediction, monday should probably be [1,0,0,0,0,0,0] . 如果要对一周中的所有天进行编码以进行预测,则monday可能应为[1,0,0,0,0,0,0] Or you use regression (0.0 - 6.0) instead of classification. 或者您使用回归(0.0-6.0)而不是分类。

But, since you used X instead of y here, I'm not sure if your provided X=['Monday','January','South'] is meant to be the input rather than the output ( y ). 但是,由于您在这里使用X而不是y ,所以我不确定您提供的X=['Monday','January','South']是输入而不是输出( y )。 If it is, you do not need a one-hot encoding and you can just encode as eg X=[0,0,2] with 如果是这样,则不需要单次编码,而可以将其编码为例如X=[0,0,2]

  • Monday 0 星期一0
  • Tuesday 1 星期二1
  • ... ...
  • January 0 一月0
  • February 1 2月1日
  • North 0 北0
  • East 1 东1
  • ... ...

I agree with @morsecodist that more information is needed for a proper answer to your question. 我同意@morsecodist的观点,即需要更多信息才能正确回答您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM