Last active
October 23, 2018 01:35
-
-
Save akornor/44e2c40a9563760b3658c621c06a7a5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import csv | |
from collections import namedtuple | |
from sklearn.linear_model import LinearRegression | |
Wine = namedtuple('Wine', ['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar', 'chlorides', 'free_sulfur_dioxide', 'total_sulfur_dioxide', 'density', 'pH', 'sulphates', 'alcohol', 'quality']) | |
def main(): | |
wines = [] | |
with open('wines.csv') as f: | |
csv_reader = csv.reader(f) | |
headers = next(csv_reader) | |
for row in csv_reader: | |
wine = Wine(*row) | |
wines.append(wine) | |
qualities = [float(wine.quality) for wine in wines] | |
print(sum(qualities)/len(qualities)) | |
residual_sugars = [float(wine.residual_sugar) for wine in wines] | |
fixed_acidity = [float(wine.fixed_acidity) for wine in wines] | |
volatile_acidity = [float(wine.volatile_acidity) for wine in wines] | |
print(max(residual_sugars)) | |
print(min(fixed_acidity)) | |
ids = list(range(len(qualities)+1)) | |
LR = LinearRegression() | |
LR.fit(list(zip(ids, volatile_acidity)), qualities) | |
print(LR.coef_) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment