简体   繁体   English

使用 Keras 进行太阳能功率预测

[英]Solar power prediction using Keras

Dataset:数据集:

数据集

The PV Yield (kWh) is my output. PV 发电量 (kWh) 是我的 output。 My model is suppose to predict this.我的 model 应该可以预测到这一点。 This is what I have done.这就是我所做的。 I have attached the image of the dataset.我附上了数据集的图像。 From AirTemp to Zenith is my X and Y is PV Yield(KW/H).从 AirTemp 到 Zenith 是我的 X,Y 是 PV 产量(KW/H)。

df=pd.read_csv("Data1.csv")

X=df.drop(['Date-PrimaryKey','output-PV Yield (kWh)'],axis=1)

Y=df['output-PV Yield (kWh)']

pca = PCA(n_components=9)

pca.fit(X_train)

X_train = pca.transform(X_train)

pca.fit(X_test)

X_test = pca.transform(X_test)  


#normalizing the input values to fall in -1 to 1

X_train = X_train/180000000.0

X_test = X_test/180000000.0


#Creating Model

model = Sequential()

model.add(Dense(15, input_shape=(9,)))

model.add(Activation('tanh'))


model.add(Dense(11))

model.add(Activation('tanh'))


model.add(Dense(1))


model.summary()

sgd = optimizers.SGD(lr=0.1,momentum=0.2)

model.compile(loss='mean_absolute_error',optimizer=sgd,metrics=['accuracy'])


#Training

model.fit(X_train, train_y, epochs=20, batch_size = 50, validation_data=(X_test, test_y))

My weights are not getting updated.我的体重没有更新。 Accuracy is zero in all epochs.所有时期的准确度为零。

The model seems OK but there are two problems I can spot fast: model 看起来不错,但我可以快速发现两个问题:

pca = PCA(n_components=9)
pca.fit(X_train)
X_train = pca.transform(X_train)
pca.fit(X_test)
X_test = pca.transform(X_test)

Anything used for transformation of the data must not be fit on testing data.任何用于数据转换的东西都不能适合测试数据。 You fit it on train samples and then use it to transform both train and test part.您将它安装在火车样本上,然后用它来转换火车和测试部分。 You should assume that you know nothing about data you will be predicting on in production, eg.您应该假设您对将在生产中预测的数据一无所知,例如。 you know nothing about tomorrows weather, results of sport matches in a month, etc. You wont be able to do so then, so you cant do so during training.你对明天的天气,一个月内的运动比赛结果等一无所知。到那时你就做不到了,所以你不能在训练的时候这样做。 Correct way:正确方法:

pca = PCA(n_components=9)
pca.fit(X_train)
X_train = pca.transform(X_train)
X_test = pca.transform(X_test)

The second very incorrect stuff you have there is here:您拥有的第二个非常不正确的东西在这里:

#normalizing the input values to fall in -1 to 1
X_train = X_train/180000000.0
X_test = X_test/180000000.0

Of course you want to normalize your data, but this way you will end up with incredibly low decimals in cases where values are low, eg.当然,您想规范化您的数据,但这样一来,在值较低的情况下,您最终会得到非常低的小数,例如。 AlbedoDaily column, and quite high values where are values high, such as SurfacePressure . AlbedoDaily列,以及相当高的值,例如SurfacePressure For such scaling you can use already defined classes such as standard scaler .对于此类缩放,您可以使用已定义的类,例如标准缩放器 The code is very simple and each column is treated independently:代码非常简单,每一列都是独立处理的:

from sklearn.preprocessing import StandardScaler
transformer = StandardScaler().fit(X_train)
X_train = transformer.transform(X_train)
X_test = transformer.transform(X_test)

You have not provided or explained what your target variable is and where you get is, there could be other problems in your code I can not see right now.您尚未提供或解释您的目标变量是什么以及您在哪里获得,您的代码中可能还有其他问题,我现在看不到。

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

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