@qoderman/

index ai

Python

No description

fork
loading
Files
  • main.py
  • submission_example.csv
  • test.csv
  • train.csv
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from sklearn.linear_model import Ridge
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
import pandas as pd
import csv
from sklearn import linear_model

df = pd.read_csv("train.csv")
output_data = df['medv']
input_data = df.drop('medv', axis=1)

model = make_pipeline(PolynomialFeatures(7), Ridge())
model.fit(input_data, output_data)



df2 = pd.read_csv("test.csv")






predictions = open('predictions1234.csv', mode='w', newline='')
prediction_writer = csv.writer(predictions)






prediction_writer.writerow(['ID','medv'])
for x in range(len(df2["ID"])):
  result = model.predict(df2.ix[[x]])
  print(result)
  print(df2["ID"][x])
  prediction_writer.writerow([df2["ID"][x],result[0]])
predictions.close()