super wyniki ewaluacji
This commit is contained in:
parent
ca74151be3
commit
96648232b5
@ -1,25 +1,48 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from os import path
|
||||
from tensorflow import keras
|
||||
import sys
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.metrics import accuracy_score, classification_report
|
||||
from sklearn.metrics import accuracy_score
|
||||
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
||||
|
||||
model = keras.models.load_model('wine_model.h5')
|
||||
print('evaluating')
|
||||
|
||||
test_df =pd.read_csv('test.csv')
|
||||
y_test = test_df.quality
|
||||
x_test = test_df.drop(['quality'], axis= 1)
|
||||
data =pd.read_csv('test.csv')
|
||||
|
||||
x_test=((x_test-x_test.min())/(x_test.max()-x_test.min())) #Normalizacja
|
||||
#########################################
|
||||
|
||||
y_pred = model.predict(x_test)
|
||||
y = data['quality']
|
||||
x = data.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 = data.join(citric_acidity).join(density_acidity)
|
||||
|
||||
print(y)
|
||||
|
||||
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)
|
||||
|
||||
##################################
|
||||
|
||||
y_pred = model.predict(scaled_x)
|
||||
|
||||
y_pred = np.around(y_pred, decimals=0)
|
||||
|
||||
results = accuracy_score(y_test,y_pred)
|
||||
results = accuracy_score(yenc,y_pred)
|
||||
with open('results.txt', 'a+', encoding="UTF-8") as f:
|
||||
f.write(str(results) +"\n")
|
||||
|
||||
|
@ -4,33 +4,47 @@ 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
|
||||
|
||||
|
||||
wine=pd.read_csv('train.csv')
|
||||
wine
|
||||
|
||||
y = wine.quality
|
||||
y.head()
|
||||
y = wine['quality']
|
||||
x = wine.drop('quality', axis=1)
|
||||
|
||||
x = wine.drop(['quality'], axis= 1)
|
||||
x.head()
|
||||
citricacid = x['fixed acidity'] * x['citric acid']
|
||||
citric_acidity = pd.DataFrame(citricacid, columns=['citric_accidity'])
|
||||
|
||||
x=((x-x.min())/(x.max()-x.min())) #Normalizacja
|
||||
density_acidity = x['fixed acidity'] * x['density']
|
||||
density_acidity = pd.DataFrame(density_acidity, columns=['density_acidity'])
|
||||
|
||||
x_train, x_test, y_train, y_test = train_test_split(x,y , test_size=0.2,train_size=0.8, random_state=21)
|
||||
|
||||
def regression_model():
|
||||
model = Sequential()
|
||||
model.add(Dense(4,activation = "relu", input_shape = (x_train.shape[1],)))
|
||||
model.add(Dense(8,activation = "relu"))
|
||||
model.add(Dense(8,activation = "relu"))
|
||||
model.add(Dense(1,activation = "relu"))
|
||||
|
||||
model.compile(optimizer = "adam", loss = "mean_squared_error")
|
||||
return model
|
||||
x = wine.join(citric_acidity).join(density_acidity)
|
||||
|
||||
model = regression_model()
|
||||
model.fit(x_train, y_train, batch_size=int(sys.argv[1]), epochs = int(sys.argv[1])) #verbose = 1
|
||||
bins = (2, 5, 8)
|
||||
gnames = ['bad', 'nice']
|
||||
y = pd.cut(y, bins = bins, labels = gnames)
|
||||
|
||||
model.save('wine_model.h5')
|
||||
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, epochs=15) #verbose = 1
|
||||
|
||||
NeuralModel.save('wine_model.h5')
|
||||
|
Loading…
Reference in New Issue
Block a user