好吧,我是4年级学生,最近我需要教自己如何为机器学习编写代码。我目前正在为一个项目使用葡萄酒数据集,并且需要使用神经网络基于11种输入来预测葡萄酒的质量。我需要将此作为回归示例。一切正常,直到我适合模型为止。我的准确性没有增加,并且保持不变。我对此很陌生,并且确定这个问题并没有那么难解决,我只是菜鸟。
到目前为止,我已经尝试研究过拟合和欠拟合,但是我认为在此处发布会很快
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_csv('wineQualityReds.csv', usecols=lambda x: 'Unnamed' not in x,) #there is a column i needed to remove here
df.head(3)
df.describe(include = 'all')
sns.pairplot(df)
X = df.iloc[:,0:11]
Y = df.iloc[:,11]
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler()
X = sc.fit_transform(X)
Y = Y.values.reshape(-1,1)
Y = sc.fit_transform(Y)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.3)
from keras import Sequential
from keras.layers import Dense
def build_regressor():
regressor = Sequential()
regressor.add(Dense(units = 11, input_dim = 11))
regressor.add(Dense(units = 11))
regressor.add(Dense(units = 1))
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error', metrics = ['mae', 'accuracy'])
return regressor
from keras.wrappers.scikit_learn import KerasRegressor
regressor = KerasRegressor(build_fn = build_regressor, batch_size = 32,
epochs = 100)
results = regressor.fit(X_train,y_train)