Libraries and Dataset¶

In [251]:
import numpy as np
import pandas as pd
import seaborn  as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, OneHotEncoder, StandardScaler,MinMaxScaler
from sklearn.model_selection import cross_val_score, GridSearchCV
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix,classification_report, ConfusionMatrixDisplay
In [252]:
dataset = pd.read_csv('data/market_cluster.csv', encoding='latin1')
In [253]:
dataset.head()
Out[253]:
Order ID Customer Name Category Sub Category City Order Date Region Sales Discount Profit State profit_margin Cluster
0 OD1 Harish Oil & Masala Masalas Vellore 11-08-2017 North 1254 0.12 401.28 Tamil Nadu 0.32 Medium
1 OD2 Sudha Beverages Health Drinks Krishnagiri 11-08-2017 South 749 0.18 149.80 Tamil Nadu 0.20 Medium
2 OD3 Hussain Food Grains Atta & Flour Perambalur 06-12-2017 West 2360 0.21 165.20 Tamil Nadu 0.07 Low
3 OD4 Jackson Fruits & Veggies Fresh Vegetables Dharmapuri 10-11-2016 South 896 0.25 89.60 Tamil Nadu 0.10 Low
4 OD5 Ridhesh Food Grains Organic Staples Ooty 10-11-2016 South 2355 0.26 918.45 Tamil Nadu 0.39 High
In [254]:
dataset = pd.DataFrame(dataset)
In [255]:
dataset.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 9994 entries, 0 to 9993
Data columns (total 13 columns):
 #   Column         Non-Null Count  Dtype  
---  ------         --------------  -----  
 0   Order ID       9994 non-null   object 
 1   Customer Name  9994 non-null   object 
 2   Category       9994 non-null   object 
 3   Sub Category   9994 non-null   object 
 4   City           9994 non-null   object 
 5   Order Date     9994 non-null   object 
 6   Region         9994 non-null   object 
 7   Sales          9994 non-null   int64  
 8   Discount       9994 non-null   float64
 9   Profit         9994 non-null   float64
 10  State          9994 non-null   object 
 11  profit_margin  9994 non-null   float64
 12  Cluster        9994 non-null   object 
dtypes: float64(3), int64(1), object(9)
memory usage: 1015.1+ KB

Data Cleaning & Preprocessing¶

In [256]:
dataset.drop(['Order ID'], axis=1, inplace=True)
In [257]:
dataset.isna().sum()
Out[257]:
Customer Name    0
Category         0
Sub Category     0
City             0
Order Date       0
Region           0
Sales            0
Discount         0
Profit           0
State            0
profit_margin    0
Cluster          0
dtype: int64
In [258]:
dataset.dropna(inplace=True)
In [259]:
def remove_outliers(data: pd.DataFrame, column: str) -> pd.Series:
    q3, q1 = np.nanpercentile(data[column], [75, 25])
    iqr = q3 - q1
    upper_bound = q3 + 1.5 * iqr
    lower_bound = q1 - 1.5 * iqr
    data = data[(data[column] > lower_bound) & (data[column] < upper_bound)]

    return data

dataset = remove_outliers(dataset, 'Discount')
dataset = remove_outliers(dataset, 'Sales')
dataset = remove_outliers(dataset, 'Profit')
In [260]:
dataset.head()
Out[260]:
Customer Name Category Sub Category City Order Date Region Sales Discount Profit State profit_margin Cluster
0 Harish Oil & Masala Masalas Vellore 11-08-2017 North 1254 0.12 401.28 Tamil Nadu 0.32 Medium
1 Sudha Beverages Health Drinks Krishnagiri 11-08-2017 South 749 0.18 149.80 Tamil Nadu 0.20 Medium
2 Hussain Food Grains Atta & Flour Perambalur 06-12-2017 West 2360 0.21 165.20 Tamil Nadu 0.07 Low
3 Jackson Fruits & Veggies Fresh Vegetables Dharmapuri 10-11-2016 South 896 0.25 89.60 Tamil Nadu 0.10 Low
4 Ridhesh Food Grains Organic Staples Ooty 10-11-2016 South 2355 0.26 918.45 Tamil Nadu 0.39 High
In [261]:
sns.histplot(dataset['Cluster'])
Out[261]:
<AxesSubplot:xlabel='Cluster', ylabel='Count'>
In [262]:
encoder = LabelEncoder()
scaler = StandardScaler()
onehot = OneHotEncoder()
minmaxscaler = MinMaxScaler()
In [263]:
dataset["Order Date"] = pd.to_datetime(dataset["Order Date"])
dataset["Order Date"] = dataset["Order Date"].dt.month
dataset["Customer Name"] = encoder.fit_transform(dataset["Customer Name"])
dataset["Category"] = encoder.fit_transform(dataset["Category"])
dataset["City"] = encoder.fit_transform(dataset["City"])
dataset["Region"] = encoder.fit_transform(dataset["Region"])
dataset["State"] = encoder.fit_transform(dataset["State"])
dataset["Sub Category"] = encoder.fit_transform(dataset["Sub Category"])

# dataset["Order Date"] = pd.to_datetime(dataset["Order Date"])
# dataset["Order Date"] = dataset["Order Date"].dt.month
# dataset["Customer Name"] = onehot.fit_transform(dataset["Customer Name"].values.reshape(-1, 1)).toarray()
# dataset["Category"] = onehot.fit_transform(dataset["Category"].values.reshape(-1, 1)).toarray()
# dataset["City"] = onehot.fit_transform(dataset["City"].values.reshape(-1, 1)).toarray()
# dataset["Region"] = onehot.fit_transform(dataset["Region"].values.reshape(-1, 1)).toarray()
# dataset["State"] = onehot.fit_transform(dataset["State"].values.reshape(-1, 1)).toarray()
# dataset["Sub Category"] = onehot.fit_transform(dataset["Sub Category"].values.reshape(-1, 1)).toarray()

dataset["Order Date"] = encoder.fit_transform(dataset["Order Date"])
In [264]:
dataset[["Sales", "Discount", "profit_margin"]] = scaler.fit_transform(dataset[["Sales", "Discount", "profit_margin"]])
dataset["Profit"] = minmaxscaler.fit_transform(dataset["Profit"].values.reshape(-1, 1))
In [265]:
class_to_numeric = {'Low': 0, 'Medium': 1, 'High': 2}
dataset['Cluster'] = [class_to_numeric[label] for label in dataset['Cluster']]
In [266]:
import joblib


joblib.dump(encoder, 'model/pre/encoder.joblib')
joblib.dump(scaler, 'model/pre/scaler.joblib')
joblib.dump(onehot, 'model/pre/onehot.joblib')
joblib.dump(minmaxscaler, 'model/pre/minmaxscaler.joblib')
Out[266]:
['model/pre/minmaxscaler.joblib']
In [267]:
dataset.head()
Out[267]:
Customer Name Category Sub Category City Order Date Region Sales Discount Profit State profit_margin Cluster
0 12 5 14 21 10 2 -0.414559 -1.430908 0.369225 0 0.595874 1
1 37 1 13 8 10 3 -1.291968 -0.627370 0.122296 0 -0.416872 1
2 14 3 0 13 5 4 1.507054 -0.225601 0.137417 0 -1.514014 0
3 15 4 12 4 9 3 -1.036563 0.310092 0.063185 0 -1.260827 0
4 28 3 18 12 9 3 1.498367 0.444015 0.877036 0 1.186643 2

Split Data and Encoder¶

In [268]:
X = dataset.drop(['Cluster','Sub Category','State','Profit','profit_margin'],axis=1)
y = dataset['Profit']
In [269]:
X.head()
Out[269]:
Customer Name Category City Order Date Region Sales Discount
0 12 5 21 10 2 -0.414559 -1.430908
1 37 1 8 10 3 -1.291968 -0.627370
2 14 3 13 5 4 1.507054 -0.225601
3 15 4 4 9 3 -1.036563 0.310092
4 28 3 12 9 3 1.498367 0.444015
In [270]:
X_train, X_temp, y_train, y_temp = train_test_split(X, y, test_size=0.2, random_state=42)
X_val, X_test, y_val, y_test = train_test_split(X_temp, y_temp, test_size=0.5, random_state=42)
In [271]:
# subset_of_data = X.sample(frac=0.05, random_state=42)  
# plt.figure(figsize=(14,7))
# plt.subplot(1,2,2)
# plt.title("Scatterplot Scaling", fontsize=18)
# sns.scatterplot(data = subset_of_data, color="red")
# plt.tight_layout()
# plt.show()
In [272]:
# plt.figure(figsize=(14,7))
# plt.subplot(1,2,2)
# plt.title("Data Scaling", fontsize=18)
# sns.kdeplot(data = X, color="red")
# plt.tight_layout()
# plt.show()
In [273]:
heatcol = X.corr()
sns.heatmap(heatcol,cmap="BrBG",annot=True)
Out[273]:
<AxesSubplot:>
In [274]:
print("Dimension of Train set",X_train.shape)
print("Dimension of Val set",X_val.shape)
print("Dimension of Test set",X_test.shape,"\n")

num_cols = X_train._get_numeric_data().columns
print("Number of numeric features:",num_cols.size)
Dimension of Train set (7960, 7)
Dimension of Val set (995, 7)
Dimension of Test set (996, 7) 

Number of numeric features: 7

ANNr¶

In [275]:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from scikeras.wrappers import KerasRegressor
In [276]:
def create_model(units=64, optimizer='adam', loss='mae'):
    model = Sequential()
    model.add(Flatten(input_shape=(X_train.shape[1], 1)))
    model.add(Dense(units, activation='relu'))
    model.compile(optimizer=optimizer, loss=loss, metrics=['mean_absolute_error'])
    
    return model
In [277]:
model = KerasRegressor(build_fn=create_model, units=32, epochs=100, batch_size=32, verbose=0)

param_grid = {
    'optimizer': ['adam', 'sgd', 'rmsprop'],
    'units': [32, 64, 128],
    'loss' : ['mae', 'mse']
}

grid = GridSearchCV(estimator=model, param_grid=param_grid, cv=2, scoring='accuracy')
grid_result = grid.fit(X_train, y_train)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 127360]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 127360]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 254720]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 254720]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 509440]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 509440]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 127360]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 127360]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 254720]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 254720]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 509440]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 509440]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 127360]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 127360]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 254720]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 254720]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 509440]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:821: UserWarning: Scoring failed. The score on this train-test partition for these parameters will be set to nan. Details: 
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 810, in _score
    scores = scorer(estimator, X_test, y_test)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 266, in __call__
    return self._score(partial(_cached_call, None), estimator, X, y_true, **_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_scorer.py", line 355, in _score
    return self._sign * self._score_func(y_true, y_pred, **scoring_kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\_param_validation.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 220, in accuracy_score
    y_type, y_true, y_pred = _check_targets(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\metrics\_classification.py", line 84, in _check_targets
    check_consistent_length(y_true, y_pred)
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\utils\validation.py", line 407, in check_consistent_length
    raise ValueError(
ValueError: Found input variables with inconsistent numbers of samples: [3980, 509440]

  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py:425: FitFailedWarning: 
18 fits failed out of a total of 36.
The score on these train-test partitions for these parameters will be set to nan.
If these failures are not expected, you can try to debug them by setting error_score='raise'.

Below are more details about the failures:
--------------------------------------------------------------------------------
18 fits failed with the following error:
Traceback (most recent call last):
  File "c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_validation.py", line 729, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py", line 760, in fit
    self._fit(
  File "c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py", line 926, in _fit
    self._check_model_compatibility(y)
  File "c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py", line 569, in _check_model_compatibility
    raise ValueError(
ValueError: loss=mse but model compiled with mae. Data may not match loss function!

  warnings.warn(some_fits_failed_message, FitFailedWarning)
c:\Users\Asus\anaconda3\lib\site-packages\sklearn\model_selection\_search.py:979: UserWarning: One or more of the test scores are non-finite: [nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan]
  warnings.warn(
c:\Users\Asus\anaconda3\lib\site-packages\scikeras\wrappers.py:915: UserWarning: ``build_fn`` will be renamed to ``model`` in a future release, at which point use of ``build_fn`` will raise an Error instead.
  X, y = self._initialize(X, y)
In [278]:
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
Best: nan using {'loss': 'mae', 'optimizer': 'adam', 'units': 32}
In [279]:
optimizer = grid_result.best_params_['optimizer']
units = grid_result.best_params_['units']
loss = grid_result.best_params_['loss']
In [280]:
model = Sequential()
model.add(Flatten(input_shape=(X_train.shape[1], 1)))
model.add(Dense(1))
model.add(Dense(units, activation='relu'))

model.compile(optimizer=optimizer, loss=loss, metrics=['mean_absolute_error'])
history = model.fit(X_train, y_train, epochs=100, batch_size=32, validation_data=(X_val, y_val))

loss = model.evaluate(X_test, y_test)
print(f'Mean Squared Error on Test Data: {loss}')
Epoch 1/100
249/249 [==============================] - 2s 4ms/step - loss: 0.3653 - mean_absolute_error: 0.3653 - val_loss: 0.2679 - val_mean_absolute_error: 0.2679
Epoch 2/100
249/249 [==============================] - 1s 3ms/step - loss: 0.2445 - mean_absolute_error: 0.2445 - val_loss: 0.2380 - val_mean_absolute_error: 0.2380
Epoch 3/100
249/249 [==============================] - 1s 3ms/step - loss: 0.2259 - mean_absolute_error: 0.2259 - val_loss: 0.2265 - val_mean_absolute_error: 0.2265
Epoch 4/100
249/249 [==============================] - 1s 3ms/step - loss: 0.2193 - mean_absolute_error: 0.2193 - val_loss: 0.2244 - val_mean_absolute_error: 0.2244
Epoch 5/100
249/249 [==============================] - 1s 3ms/step - loss: 0.2126 - mean_absolute_error: 0.2126 - val_loss: 0.2148 - val_mean_absolute_error: 0.2148
Epoch 6/100
249/249 [==============================] - 1s 3ms/step - loss: 0.2080 - mean_absolute_error: 0.2080 - val_loss: 0.2119 - val_mean_absolute_error: 0.2119
Epoch 7/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1975 - mean_absolute_error: 0.1975 - val_loss: 0.1926 - val_mean_absolute_error: 0.1926
Epoch 8/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1857 - mean_absolute_error: 0.1857 - val_loss: 0.1891 - val_mean_absolute_error: 0.1891
Epoch 9/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1816 - mean_absolute_error: 0.1816 - val_loss: 0.1815 - val_mean_absolute_error: 0.1815
Epoch 10/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1722 - mean_absolute_error: 0.1722 - val_loss: 0.1664 - val_mean_absolute_error: 0.1664
Epoch 11/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1590 - mean_absolute_error: 0.1590 - val_loss: 0.1552 - val_mean_absolute_error: 0.1552
Epoch 12/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1524 - mean_absolute_error: 0.1524 - val_loss: 0.1535 - val_mean_absolute_error: 0.1535
Epoch 13/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1509 - mean_absolute_error: 0.1509 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 14/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1508 - mean_absolute_error: 0.1508 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 15/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 16/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1507 - mean_absolute_error: 0.1507 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 17/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 18/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1533 - val_mean_absolute_error: 0.1533
Epoch 19/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 20/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 21/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 22/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 23/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 24/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 25/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 26/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 27/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1533 - val_mean_absolute_error: 0.1533
Epoch 28/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1535 - val_mean_absolute_error: 0.1535
Epoch 29/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 30/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 31/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 32/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 33/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1534 - val_mean_absolute_error: 0.1534
Epoch 34/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 35/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 36/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 37/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1503 - mean_absolute_error: 0.1503 - val_loss: 0.1545 - val_mean_absolute_error: 0.1545
Epoch 38/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 39/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 40/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 41/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 42/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1534 - val_mean_absolute_error: 0.1534
Epoch 43/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 44/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1536 - val_mean_absolute_error: 0.1536
Epoch 45/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 46/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 47/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 48/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 49/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 50/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 51/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 52/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 53/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 54/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 55/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 56/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 57/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1536 - val_mean_absolute_error: 0.1536
Epoch 58/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1535 - val_mean_absolute_error: 0.1535
Epoch 59/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1538 - val_mean_absolute_error: 0.1538
Epoch 60/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 61/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 62/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 63/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 64/100
249/249 [==============================] - 1s 4ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 65/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 66/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 67/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 68/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 69/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 70/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 71/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 72/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 73/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 74/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1507 - mean_absolute_error: 0.1507 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 75/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 76/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 77/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 78/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 79/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 80/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 81/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 82/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 83/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 84/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1536 - val_mean_absolute_error: 0.1536
Epoch 85/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1538 - val_mean_absolute_error: 0.1538
Epoch 86/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1531 - val_mean_absolute_error: 0.1531
Epoch 87/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 88/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 89/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1534 - val_mean_absolute_error: 0.1534
Epoch 90/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1507 - mean_absolute_error: 0.1507 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 91/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 92/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 93/100
249/249 [==============================] - 1s 2ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1541 - val_mean_absolute_error: 0.1541
Epoch 94/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1534 - val_mean_absolute_error: 0.1534
Epoch 95/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1530 - val_mean_absolute_error: 0.1530
Epoch 96/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 97/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1532 - val_mean_absolute_error: 0.1532
Epoch 98/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1506 - mean_absolute_error: 0.1506 - val_loss: 0.1529 - val_mean_absolute_error: 0.1529
Epoch 99/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1505 - mean_absolute_error: 0.1505 - val_loss: 0.1528 - val_mean_absolute_error: 0.1528
Epoch 100/100
249/249 [==============================] - 1s 3ms/step - loss: 0.1504 - mean_absolute_error: 0.1504 - val_loss: 0.1537 - val_mean_absolute_error: 0.1537
32/32 [==============================] - 0s 3ms/step - loss: 0.1483 - mean_absolute_error: 0.1483
Mean Squared Error on Test Data: [0.1483268290758133, 0.1483268290758133]
In [281]:
from tensorflow.keras.utils import plot_model
model.summary()
plot_model(model, to_file='mlp-mnist.png', show_shapes=True)
Model: "sequential_198"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 flatten_198 (Flatten)       (None, 7)                 0         
                                                                 
 dense_207 (Dense)           (None, 1)                 8         
                                                                 
 dense_208 (Dense)           (None, 32)                64        
                                                                 
=================================================================
Total params: 72 (288.00 Byte)
Trainable params: 72 (288.00 Byte)
Non-trainable params: 0 (0.00 Byte)
_________________________________________________________________
You must install pydot (`pip install pydot`) and install graphviz (see instructions at https://graphviz.gitlab.io/download/) for plot_model to work.
In [282]:
import joblib
joblib.dump(model, 'model/annr_model.pkl')
INFO:tensorflow:Assets written to: C:\Users\Asus\AppData\Local\Temp\tmpfmrf8gyu\assets
INFO:tensorflow:Assets written to: C:\Users\Asus\AppData\Local\Temp\tmpfmrf8gyu\assets
Out[282]:
['model/annr_model.pkl']
In [283]:
plt.figure(figsize=(12, 5))
plt.subplot(1, 2, 1)
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Loss over epochs')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Validation'], loc='best')

plt.subplot(1, 2, 2)
plt.plot(history.history['mean_absolute_error'])
plt.plot(history.history['val_mean_absolute_error'])
plt.title('Accuracy over epochs')
plt.ylabel('Accuracy')
plt.xlabel('Epoch')
plt.legend(['Train', 'Validation'], loc='best')

plt.tight_layout()
plt.show()
In [284]:
y_test = y_test.values.reshape(-1, 1)
In [285]:
predictions_scaled = model.predict(X_test)
y_pred = minmaxscaler.inverse_transform(predictions_scaled)
y_test = minmaxscaler.inverse_transform(y_test)

y_pred = y_pred[:, 0].reshape(-1, 1)
32/32 [==============================] - 0s 2ms/step
In [286]:
from sklearn.metrics import mean_squared_error, mean_absolute_error
from sklearn.metrics import r2_score

mse = mean_squared_error(y_test, y_pred)
mae = mean_absolute_error(y_test, y_pred)
rmse = np.sqrt(mse)
r2 = r2_score(y_test, y_pred)


print(f'Mean Squared Error: {mse}')
print(f'Mean Absolute Error: {mae}')
print(f'Root Mean Squared Error: {rmse} \n')
print(f'R-squared: {r2}')
print(f'accuracy : {r2}')
Mean Squared Error: 34741.35692055902
Mean Absolute Error: 151.06479969438297
Root Mean Squared Error: 186.39033483675868 

R-squared: 0.3199025138631294
accuracy : 0.3199025138631294
In [287]:
plt.scatter(y_test, y_pred, label="Predicted", color='red')
plt.plot([min(y_test), max(y_test)], [min(y_test), max(y_test)], linestyle='--', color='blue', label='Perfect Prediction')  # Adding a line for perfect prediction
plt.xlabel('True Values')
plt.ylabel('Predictions')
plt.legend()
plt.title('Actual vs Predicted Values')
plt.show()
In [288]:
# Visualisasi
plt.figure(figsize=(12, 6))

# Plot nilai sebenarnya
plt.plot(y_test, label='Actual', color='blue')

# Plot prediksi
plt.plot(y_pred, label='Predicted', color='red')

plt.title('LSTM Regression - Actual vs Predicted')
plt.xlabel('Time')
plt.ylabel('Value')
plt.legend()
plt.show()
In [289]:
# Grouping and averaging 'y_test' and 'y_pred' values
group_size = 10  # Define the size of each group
averaged_y_test = [np.mean(y_test[i:i + group_size]) for i in range(0, len(y_test), group_size)]
averaged_y_pred = [np.mean(y_pred[i:i + group_size]) for i in range(0, len(y_pred), group_size)]

# Plotting the averaged values
plt.figure(figsize=(12, 6))
plt.plot(averaged_y_test, label='Actual (Averaged)', color='blue')
plt.plot(averaged_y_pred, label='Predicted (Averaged)', color='red')

plt.title('RNN Regression - Averaged Actual vs Predicted')
plt.xlabel('Grouped Datapoints')
plt.ylabel('Average Value')
plt.legend()
plt.show()