File size: 1,332 Bytes
9248464 f5d939c 9248464 f5d939c 9248464 f5d939c 9248464 f5d939c 9248464 f5d939c 9248464 f5d939c 9248464 088d766 f5d939c 9248464 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import os
import numpy as np
import pandas as pd
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import PowerTransformer
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import f1_score
import argparse
import joblib
def train(dataset):
df=dataset.copy()
features=["Torque(Nm)","Hydraulic_Pressure(bar)","Cutting(kN)","Coolant_Pressure(bar)","Spindle_Speed(RPM)","Coolant_Temperature","Downtime"]
df=df[features]
df.dropna(inplace=True,ignore_index=True)
X=df.drop("Downtime",axis=1)
y=df["Downtime"]
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.20,random_state=42,stratify=y)
transform=PowerTransformer()
X_train=transform.fit_transform(X_train)
X_test=transform.transform(X_test)
encoder=LabelEncoder()
y_train=encoder.fit_transform(y_train)
y_test=encoder.transform(y_test)
model=RandomForestClassifier(random_state=42)
model.fit(X_train,y_train)
predict=model.predict(X_test)
return {"model":model,
"encoder":encoder,
"transform":transform,
"Accuracy":f"{accuracy_score(y_test,predict):4f}",
"F1_Score":f"{f1_score(y_test,predict):4f}"}
|