Я написал регрессионную модель RandomForest в классе Modelrf. Это отдельный python файл с именем RandomForest.py
Код для RandomForest.py:
from sklearn.ensemble import RandomForestRegressor
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np
import pandas as pd
class Modelrf():
def __init__(self, train = "train.csv", test = "test.csv"):
self.X_train = pd.read_csv(train)
self.X_test = pd.read_csv(test)
self.linear_reg = LinearRegression()
self.random_forest = RandomForestRegressor()
def split(self):
self.X_train.dropna(axis=0, subset=['salary'], inplace=True)
self.X_test.dropna(axis=0, subset=['salary'], inplace=True)
self.y_train = self.X_train.final_hourly_fee
self.y_test = self.X_test.final_hourly_fee
def fit(self):
self.model = self.random_forest.fit(self.X_train, self.y_train)
def predict(self):
self.result = self.random_forest.predict(self.X_test)
return self.result
if __name__ == '__main__':
model_instance = Modelrf()
model_instance.split()
model_instance.fit()
model_instance.predict()
print(model_instance.result)
print("Accuracy: ", model_instance.model.score(model_instance.X_test, model_instance.y_test))
output = pd.DataFrame({'Id': model_instance.X_test.index,'Y Original': model_instance.y_test, 'Y predicted':model_instance.result})
output.to_csv('outputTest.txt', index=False)
Теперь я импортировал класс Modelrf в main.py
Код для main.py:
import pandas as pd
import numpy as np
from RandomForest import Modelrf
from RandomForest import X_test,y_test,result
if __name__ == '__main__':
model_instance = Modelrf()
model_instance.split()
model_instance.fit()
model_instance.predict()
print(model_instance.result)
print("Accuracy: ", model_instance.model.score(model_instance.X_test, model_instance.y_test))
output = pd.DataFrame({'Id': model_instance.X_test.index,'Y Original': model_instance.y_test, 'Y predicted':model_instance.result})
output.to_csv('outputTest.txt', index=False)
Я хочу включить CI / CD на gitlab, как я могу написать свой код файла'.gitlab-ci.yml '?