-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (36 loc) · 1.36 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pandas
import numpy
from sklearn.linear_model import LinearRegression
data = pandas.read_csv('dataset.csv')
latest = data.loc[data['year'] == data['year'].iloc[-1]]
rate = data.iloc[latest.index[0], 1]
yr = data.iloc[latest.index[0], 0]
rates = data['exchangeRate']
lr = LinearRegression()
# USD into INR
def predictByLatest(year):
previousYearRate = data.iloc[latest.index[0]-1, 1]
diff = year - yr
print(f'Exchange Rate (by Latest) of India in {year} will be ₹{str(round(rate + (rate - previousYearRate) * diff))}')
def predictByAverage(year):
avg = numpy.std(rates)
diff = year - yr
print(f'Exchange Rate (by Average) of India in {year} will be ₹{str(round(rate + (avg * diff)))}')
def predictByLast3(year):
latestThree = numpy.array(rates[len(rates)-3:])
avg = numpy.std(latestThree)
diff = year - yr
print(f'Exchange Rate (by Avg of last 3) of India in {year} will be ₹{str(round(rate + (avg * diff)))}')
def predictByLinearRegression(year):
X = data[['year']]
y = data['exchangeRate']
lr.fit(X, y)
prediction = lr.predict([[year]])
print(f'Exchange Rate (by Linear Regression) of India in {year} will be ₹{round(prediction[0])}')
def predict(year):
predictByLast3(year)
predictByAverage(year)
predictByLatest(year)
predictByLinearRegression(year)
predict(2050)
print('\n')