• + 0 comments

    Polynomial Regression wasn't really needed..

    If you copy the data provided and plot it -- the solution is pretty clear.

    `

    !/bin/python3

    import math import os import random import re import sys from sklearn.linear_model import LinearRegression

    if name == 'main': timeCharged = float(input().strip()) battery, duration = [], [] with open('trainingdata.txt', 'r') as inf: for line in inf.readlines(): x, y = line.replace('\n', '').split(',') battery.append(float(x)) duration.append(float(y))

    lr = LinearRegression()
    # Split the data
    X, Y = [], []
    for x, y in zip(battery, duration):
        if x < 4.0:
            X.append([x])
            Y.append(y)
    
    lr.fit(X, Y)
    
    # predict
    print(lr.predict([[timeCharged]])[0] if timeCharged < 4 else 8.0)```