-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from milank94/model-training-update
Model training update
- Loading branch information
Showing
6 changed files
with
84 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
name: motor-fault-classification | ||
channels: | ||
- defaults | ||
- conda-forge | ||
dependencies: | ||
- pip>=8.1.2 | ||
- python=3.8.8 | ||
- numpy=1.20.2 | ||
- pandas=1.2.3 | ||
- keras=2.4.3 | ||
- matplotlib=3.4.1 | ||
- scikit-learn=0.24.2 | ||
- matplotlib=3.4.1 | ||
- scipy=1.6.3 | ||
- pip: | ||
- tensorflow>=0.12.0rc1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
Any config specific to model training step goes here. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
# Output data path | ||
OUTPUT_DATA_DIR = Path('./output') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from pathlib import Path | ||
import numpy as np | ||
import pandas as pd | ||
from sklearn.metrics import accuracy_score | ||
from tensorflow.keras.models import load_model | ||
from data_acquisition.main import get_save_data | ||
from data_processing.main import get_save_train_test_data | ||
import model_eval_config as config | ||
|
||
# Load the data | ||
dataset = get_save_data() | ||
|
||
# Process the data and train/test split | ||
train_test_data = get_save_train_test_data(dataset) | ||
|
||
# Prepare the data | ||
X_test = np.array(train_test_data.X_test) | ||
y_test = np.array(train_test_data.y_test) | ||
|
||
# Loading the model and checking accuracy on the test data | ||
model_path = config.OUTPUT_DATA_DIR / Path('best_model.pkl') | ||
model = load_model(model_path) | ||
test_preds = np.argmax(model.predict(X_test), axis=-1) | ||
print(accuracy_score(y_test, test_preds)) | ||
|
||
# Comparing the actual values versus the predicted values | ||
data_dict = { | ||
0: 'normal', | ||
1: 'horizontal misalignment', | ||
2: 'imbalance', | ||
3: 'vertical misalignment', | ||
4: 'overhang', | ||
5: 'underhang' | ||
} | ||
results = pd.DataFrame([y_test, test_preds]).T | ||
results.columns = ['Actual', 'Prediction'] | ||
results.applymap(lambda x: data_dict[x]) | ||
|
||
print(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters