- numpy - matplotlib - scikit-learn - pandas - panel==0.13.1a2 - paths: - ./test_module.py
기본사용방법 결과
import matplotlib.pyplot as plt import numpy as np import pandas as pd from test_module import check from sklearn.linear_model import LinearRegression print(check(1,100)) x = np.random.randn(1000) y = np.random.randn(1000) fig, ax = plt.subplots() ax.scatter(x, y) fig pyscript&ML 비만도 알아보기
이곳에 키와 몸무게를 입력해주세요(저장되지 않습니다)
from sklearn.linear_model import LogisticRegression from sklearn.preprocessing import LabelEncoder, StandardScaler from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split, cross_val_score import pandas as pd from js import console def info_to_df(height, weight, gender): height, weight = height / 100, weight / 100 check = pd.DataFrame(columns=["Height", "Weight", "gender"]) data_to_insert = {"Height": height, "Weight": weight, "gender": gender} infodf = check.append(data_to_insert, ignore_index=True) return infodf def make_ml_answer(*args,**kwargs): data = pd.DataFrame([['Male',174,96,4], ['Male',189,87,2], ['Female',185,110,4], ['Male',149,61,3], ['Male',189,104,3], ['Male',147,92,5], ['Male',154,111,5], ['Male',174,90,3], ['Female',169,103,4], ['Male',195,81,2], ['Female',159,80,4], ['Female',192,101,3], ['Male',155,51,2], ['Male',191,79,2], ['Female',153,107,5], ['Female',157,110,5], ['Male',140,129,5], ['Male',144,145,5], ['Male',172,139,5], ['Male',157,110,5], ['Female',153,149,5], ['Female',169,97,4], ['Female',195,104,3], ['Male',149,61,3]], columns = ['Gender','Height','Weight','Index']) df = data le = LabelEncoder() df["gender"] = le.fit_transform(df["Gender"]) df["Height"] = df["Height"] / 100 df["Weight"] = df["Weight"] / 100 X = df.drop(["Index", "Gender"], axis="columns") y = df["Index"] X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15) model = KNeighborsClassifier(n_neighbors=5) test = model.fit(X_train, y_train) string_height = document.getElementById('height').value; string_weight = document.getElementById('weight').value; string_gender = document.getElementById('gender').value; check_height = int(round(float(string_height))) check_weight = int(round(float(string_weight))) check_gender = int(round(float(string_gender))) console.log(check_height); console.log(check_weight); console.log(check_gender); console.log("test",int(check_height)); height,weight,gender = int(check_height),int(check_weight), int(check_gender) print("키몸무게성별 잘나오나??",height,weight,gender) print("키몸무게성별 잘나오나??",type(height),type(weight),gender) if height: print("키 나옴??") prediction = test.predict(info_to_df(height, weight, gender)) print("prediction",prediction) prediction_dict = {1: "깡마름", 2: "마름", 3: "보통", 4: "통통", 5: "뚱뚱"} prediction_name = prediction_dict[prediction[0]] print("결과값:",prediction_name) pyscript.write("result",prediction_name)
cm 몸무게 kg 성별 남자:1 / 여자:2