auta-public/.ipynb_checkpoints/solution-checkpoint.ipynb

252 lines
5.0 KiB
Plaintext
Raw Normal View History

2021-05-06 11:28:34 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"from pathlib import Path\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from sklearn.linear_model import LinearRegression"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## TRENING"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"NAMES = [\"Price\",\"Mileage\",\"Year\",\"Brand\",\"EngineType\",\"EngineCapacity\"]\n",
"TRAIN_BASE = pd.read_csv(\"train/train.tsv\", sep ='\\t', names=NAMES)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"Y_TRAIN = np.array(TRAIN_BASE[\"Price\"])\n",
"X_TRAIN = np.array(TRAIN_BASE[[\"Mileage\",\"Year\",\"EngineCapacity\"]])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"MODEL = LinearRegression().fit(X_TRAIN,Y_TRAIN)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## DEV-0"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"NAMES = [\"Mileage\",\"Year\",\"Brand\",\"EngineType\",\"EngineCapacity\"]\n",
"FILE_BASE = pd.read_csv(\"dev-0/in.tsv\", sep ='\\t', names=NAMES)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"X_TEST = np.array(FILE_BASE[[\"Mileage\",\"Year\",\"EngineCapacity\"]])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"Y_TEST = MODEL.predict(X_TEST)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"VALUES = np.array2string(Y_TEST, precision=5, separator='\\n',suppress_small=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"VALUES = VALUES.split(\".\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"OUTFILE = open(\"dev-0/out.tsv\", \"w\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"for x in VALUES:\n",
" RESULT = x.replace(\" \",\"\")\n",
" RESULT = RESULT.replace(\"[\",\"\")\n",
" RESULT = RESULT.replace(\"]\",\"\")\n",
" OUTFILE.write(str(RESULT)+\"\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"OUTFILE.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## TEST A"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"NAMES = [\"Mileage\",\"Year\",\"Brand\",\"EngineType\",\"EngineCapacity\"]\n",
"FILE_BASE = pd.read_csv(\"test-A/in.tsv\", sep ='\\t', names=NAMES)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"X_TEST = np.array(FILE_BASE[[\"Mileage\",\"Year\",\"EngineCapacity\"]])"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"Y_TEST = MODEL.predict(X_TEST)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"VALUES = np.array2string(Y_TEST, precision=5, separator='\\n',suppress_small=True)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"VALUES = VALUES.split(\".\\n\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"OUTFILE = open(\"test-A/out.tsv\", \"w\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"for x in VALUES:\n",
" RESULT = x.replace(\" \",\"\").replace(\"[\",\"\").replace(\"]\",\"\")\n",
" OUTFILE.write(str(RESULT) )"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"OUTFILE.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}