def train(cls, handler, app_id, krequest, dfe): autorun = make_autorun(dfe, feature_type_estimation=False) descriptions = autorun.execute() model = autorun.result() score = 0 if model is None else model.score messages = [] for i, d in enumerate(descriptions): if i == len(descriptions) - 1 and model is None: message = {"error": 1, "message": d.desc} else: message = {"error": 0, "message": d.desc} messages.append(message) image = b"" if model is None else model.describe().picture.to_base64() result = { "score": score, "messages": messages, "image": image.decode("utf-8") } predictor = autorun.to_predictor() predictor.save_to_env(krequest.env, app_id) handler.write(result)
def test_autorun(self): print("AutoRun --------------") app = Application() dfe = app.load(self.APP_ID) dfe.target = "家賃" dfe.drop("物件名") dfe.drop("担当者") autorun = make_autorun(dfe, feature_type_estimation=False) descriptions = autorun.execute() for d in descriptions: print(d)
def test_analyst(self): df = pd.read_csv(self.FILE_NAME) autorun = make_autorun(df) autorun.dfe.target = "Survived" autorun.dfe.drop("PassengerId") autorun.dfe.drop("Ticket") autorun.dfe.drop("Name") descriptions = autorun.execute() for d in descriptions: print(d) result = autorun.result() print(result.describe().picture.path)
def test_autorun_from_request(self): print("AutoRun from Request --------------") request = json.loads(KINTONE_REQUEST.replace("###", str(self.APP_ID))) krequest = kintoneRequest() dfe = krequest.request_to_dfe(request) dfe.to_categorical(["向き"]) autorun = make_autorun(dfe, feature_type_estimation=False) descriptions = autorun.execute() for d in descriptions: print(d) print("Predict from kintone Request --------------") record = json.loads(KINTONE_RECORD.replace("###", str(self.APP_ID))) df = krequest.record_to_df(record) predictor = autorun.to_predictor() pred = predictor.predict(df) print("estimated value: {}".format(pred))
def test_classifier_predictor(self): df = pd.read_csv(self.FILE_NAME) autorun = make_autorun(df) autorun.dfe.target = "Survived" autorun.dfe.drop("PassengerId") autorun.dfe.drop("Ticket") autorun.dfe.drop("Name") descriptions = autorun.execute() for d in descriptions: print(d) predictor = autorun.to_predictor() path = os.path.dirname(__file__) saved_path = predictor.save(path, "test_predictor") predictor = Predictor.load(path, "test_predictor") shutil.rmtree(saved_path) df2 = pd.read_csv(self.FILE_NAME) y_true = df2["Survived"] pred = predictor.predict(df2) score = accuracy_score(y_true, pred) print(score)