modify script

This commit is contained in:
nlitkowski 2021-05-18 22:44:46 +02:00
parent 721fd15609
commit 3ebd13aca1
3 changed files with 2008 additions and 2006 deletions

File diff suppressed because it is too large Load Diff

14
main.py
View File

@ -11,6 +11,7 @@ TRAIN_DIR = "train"
TRAIN_FILE_NAME = "train.tsv" TRAIN_FILE_NAME = "train.tsv"
VALUE_SEP = "\t" VALUE_SEP = "\t"
LINE_SEP = "\n" LINE_SEP = "\n"
CATEGORY_TYPE = "category"
def main(dirname: str): def main(dirname: str):
@ -19,6 +20,7 @@ def main(dirname: str):
X, Y = get_train_data(names) X, Y = get_train_data(names)
clf = LinearRegression().fit(X, Y) clf = LinearRegression().fit(X, Y)
clf.predict(get_input_data(dirname, names)).tofile(os.path.join( clf.predict(get_input_data(dirname, names)).tofile(os.path.join(
dirname, OUT_FILE_NAME), sep=LINE_SEP) dirname, OUT_FILE_NAME), sep=LINE_SEP)
@ -27,10 +29,9 @@ def get_train_data(names: list):
train_path = os.path.join(MAIN_DIR, TRAIN_DIR, TRAIN_FILE_NAME) train_path = os.path.join(MAIN_DIR, TRAIN_DIR, TRAIN_FILE_NAME)
check_file(train_path) check_file(train_path)
train_data = process_input(pandas.read_csv( train_data = process_input(pandas.read_csv(
train_path, header=None, sep=VALUE_SEP, names=names), names) train_path, header=None, sep=VALUE_SEP, names=names))
train_data = train_data.loc[(train_data[names[0]] > 1000)] train_data = train_data.loc[(train_data[names[0]] > 1000)]
train_data = train_data.loc[(train_data[names[1]] > 100)]
X = train_data.loc[:, train_data.columns != names[0]] X = train_data.loc[:, train_data.columns != names[0]]
Y = train_data[names[0]] Y = train_data[names[0]]
@ -41,12 +42,13 @@ def get_train_data(names: list):
def get_input_data(dirname, names): def get_input_data(dirname, names):
in_path = os.path.join(dirname, IN_FILE_NAME) in_path = os.path.join(dirname, IN_FILE_NAME)
check_file(in_path) check_file(in_path)
return process_input(pandas.read_csv(in_path, header=None, sep=VALUE_SEP, names=names[1:]), names) return process_input(pandas.read_csv(in_path, header=None, sep=VALUE_SEP, names=names[1:]))
def process_input(df, names): def process_input(df):
df = df.drop([names[3]], axis=1) for c in df.select_dtypes(include=object).columns.values:
return pandas.get_dummies(df, columns=[names[4]]) df[c] = df[c].astype(CATEGORY_TYPE).cat.codes
return df
def get_names() -> list: def get_names() -> list:

File diff suppressed because it is too large Load Diff