Import Library Python
Import Library Python
for sd in setdata:
dfx = df[sd]
print(dfx.head())
dfx.to_csv("datasets/dataset"+str(no)+".csv")
##############
# Mendeteksi dan menampilkan outliers
outliers, lower_bound, upper_bound = detect_and_plot_outliers(df,
'wh', 'static/outlier'+str(no)+'.png')
# Mengatasi outliers
dfx = handle_outliers(df, 'wh', method='remove')
print("DataFrame after handling outliers:\n", dfx)
##############
X = dfx.drop(columns=['wh'])
y = dfx['wh']
train_size : .08
test_size : 0.2
menunjukkan jumlah data perbandingan antara data training dan data testing.
Hidden_layer : 1000
Max_iteration : 1000
Random state = 42
TRAIN SVM
def train_svm():
df = pd.read_csv('dataset.csv', sep=",")
df.set_index('no', inplace=True)
df = df.loc[df['wh'] <= 17500]
no = 0
rmse = []
for sd in setdata:
dfx = df[sd]
print(dfx.head())
dfx.to_csv("datasets/dataset" + str(no) + ".csv")
X = dfx.drop(columns=['wh'])
y = dfx['wh']
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
plt.figure(figsize=(8, 6))
plt.scatter(y_test, y_pred, alpha=0.7)
plt.xlabel('True Values ' + str(no))
plt.ylabel('Predictions ' + str(no))
plt.title('True vs Predicted Values ' + str(no))
plt.tight_layout()
plt.grid(True)
cm_img_path = 'static/images/svm_true_vs_pred_' + str(no) + '.png'
plt.savefig(cm_img_path)
plt.close()
no += 1
train_size : 0.8
test_size : 0.2
kernel : rbf
C : 100
Gamma : 0.1
Epsilon : 0.1
ANN GA
def train_ann_ga():
# Membaca DataFrame dari file CSV
df = pd.read_csv('dataset.csv', sep=",")
df.set_index('no', inplace=True)
df = df.loc[df['wh'] <= 17500]
# Membuat kolom x1, x2, x3, suhu, kelembapan, dan angin
df['x1'] = (df['x11'] + df['x12'] + df['x13'] + df['x14'] +df['x15'] +
df['x16'])
df['x2'] = (df['x21'] + df['x22'])
df['x3'] = (df['x31'] + df['x32'] + df['x33'] + df['x34'] +df['x35'] +
df['x36'] + df['x37'])
no = 0
rmse=[]
for sd in setdata:
dfx = df[sd]
print(dfx.head())
dfx.to_csv("datasets/dataset"+str(no)+".csv")
outliers, lower_bound, upper_bound = detect_and_plot_outliers(df,
'wh', 'static/outlier'+str(no)+'.png')
# Mengatasi outliers
dfx = handle_outliers(df, 'wh', method='remove')
print("DataFrame after handling outliers:\n", dfx)
X = dfx.drop(columns=['wh'])
y = dfx['wh']
#####GAAAAA
X, y = make_regression(n_samples=100, n_features=2, noise=0.1)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2, random_state=42)
y_pred=ga.y_pred
rmse.append(ga.best_rmse)
r2 = r2_score(ga.y_test, ga.y_pred)
n_samples =100
n_features : 2
noise : 0.1
train_size : 0.8
test_size : 0.2
random_state : 42
population_size : 10
generations : 20
mutation_rate : 0.1
SVM GA
def train_svm_ga():
# Membaca DataFrame dari file CSV
df = pd.read_csv('dataset.csv', sep=",")
df.set_index('no', inplace=True)
df = df.loc[df['wh'] <= 17500]
# Membuat kolom x1, x2, x3, suhu, kelembapan, dan angin
df['x1'] = (df['x11'] + df['x12'] + df['x13'] + df['x14'] + df['x15'] +
df['x16'])
df['x2'] = (df['x21'] + df['x22'])
df['x3'] = (df['x31'] + df['x32'] + df['x33'] + df['x34'] + df['x35'] +
df['x36'] + df['x37'])
no = 0
rmse=[]
for sd in setdata:
dfx = df[sd]
print(dfx.head())
dfx.to_csv("datasets/dataset"+str(no)+".csv")
##############
# Mendeteksi dan menampilkan outliers
outliers, lower_bound, upper_bound = detect_and_plot_outliers(df,
'wh', 'static/outlier'+str(no)+'.png')
# Mengatasi outliers
dfx = handle_outliers(df, 'wh', method='remove')
print("DataFrame after handling outliers:\n", dfx)
##############
X = dfx.drop(columns=['wh'])
y = dfx['wh']
#####GAAAAA
X, y = make_regression(n_samples=100, n_features=2, noise=0.1)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2, random_state=42)
y_pred=ga.y_pred
rmse.append(ga.best_rmse)
r2 = r2_score(ga.y_test, ga.y_pred)