Я не знаю, как решить эту проблему, вы можете мне помочь с этим? Я пытался переписать весь, но мне это не помогло. Я посмотрел несколько фиксов и попытался это исправить, но мне это не помогло. Можете ли вы сказать, что я делаю неправильно?
File "/home/k6zma/Документы/maks/main.py", line 56, in <module>
main()
File "/home/k6zma/Документы/maks/main.py", line 54, in main
print(tumor_working._report_GaussianNB())
File "/home/k6zma/Документы/maks/main.py", line 47, in _report_GaussianNB
report_GaussianNB = classification_report(self.y_train.values, self.pred_train_GaussianNB)
AttributeError: 'Tumor' object has no attribute 'y_train'
import numpy as np
import pandas as pd
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import classification_report
class Tumor:
def _init_(self, y_train):
self.cancer = load_breast_cancer()
self.cancer_df = self._table()
self.X_train, self.X_test, self.y_train, self.y_test = self._data_storage()
self.GaussianNB_model = self._GaussianNB_model()
self.pred_train_GaussianNB = self._GaussianNB_predict()
def _table(self):
cancer_df = pd.DataFrame(self.cancer.data, columns = self.cancer.feature_names)
cancer_df['target']= self.cancer.target
return cancer_df
def _data_storage(self):
X_data = self.cancer_df.drop(self.cancer_df.columns[-1], axis = 1)
y_data = self.cancer_df[self.cancer_df.columns[-1]]
X_train, X_test, y_train, y_test = train_test_split(X_data, y_data, test_size=0.2, random_state=42)
return X_train, X_test, y_train, y_test
def _GaussianNB_model(self):
GaussianNB_model = GaussianNB()
GaussianNB_model.fit(self.X_train,self.y_train)
return GaussianNB_model
def _GaussianNB_predict(self):
pred_train_GaussianNB = self.GaussianNB_model.predict(self.X_train)
return pred_train_GaussianNB
def _report_GaussianNB(self):
report_GaussianNB = classification_report(self.y_train.values, self.pred_train_GaussianNB)
return report_GaussianNB
def main():
tumor_working = Tumor()
print(tumor_working._report_GaussianNB())
if __name__ == "__main__":
main()