55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from tensorflow.keras.models import Sequential, load_model
|
|
from tensorflow.keras.layers import Dense
|
|
from sklearn.metrics import accuracy_score, classification_report
|
|
import pandas as pd
|
|
from sklearn.model_selection import train_test_split
|
|
import numpy as np
|
|
import sys
|
|
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
|
from tensorflow.keras.optimizers import Adam
|
|
from sacred.observers import FileStorageObserver
|
|
from sacred import Experiment
|
|
from datetime import datetime
|
|
|
|
|
|
wine=pd.read_csv('train.csv')
|
|
|
|
y = wine['quality']
|
|
x = wine.drop('quality', axis=1)
|
|
|
|
citricacid = x['fixed acidity'] * x['citric acid']
|
|
citric_acidity = pd.DataFrame(citricacid, columns=['citric_accidity'])
|
|
|
|
density_acidity = x['fixed acidity'] * x['density']
|
|
density_acidity = pd.DataFrame(density_acidity, columns=['density_acidity'])
|
|
|
|
|
|
x = wine.join(citric_acidity).join(density_acidity)
|
|
|
|
bins = (2, 5, 8)
|
|
gnames = ['bad', 'nice']
|
|
y = pd.cut(y, bins = bins, labels = gnames)
|
|
|
|
enc = LabelEncoder()
|
|
yenc = enc.fit_transform(y)
|
|
|
|
scale = StandardScaler()
|
|
scaled_x = scale.fit_transform(x)
|
|
|
|
NeuralModel = Sequential([
|
|
Dense(128, activation='relu', input_shape=(14,)),
|
|
Dense(32, activation='relu'),
|
|
Dense(64, activation='relu'),
|
|
Dense(64, activation='relu'),
|
|
Dense(64, activation='relu'),
|
|
Dense(1, activation='sigmoid')
|
|
])
|
|
|
|
rms = Adam(lr=0.0003)
|
|
|
|
NeuralModel.compile(optimizer=rms, loss='binary_crossentropy', metrics=['accuracy'])
|
|
|
|
NeuralModel.fit(scaled_x, yenc, batch_size=int(sys.argv[1]), epochs = int(sys.argv[2])) #verbose = 1
|
|
|
|
NeuralModel.save('wine_model.h5')
|