import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
Run to view results
import pandas as pd
import numpy as np
import altair as alt
Run to view results
data = pd.read_csv('https://raw.githubusercontent.com/aso-uts/labs_datasets/main/36106-mlaa/lab01/ex1/salary_data.csv')
Run to view results
data
Run to view results
scatter_chart = alt.Chart(data).mark_circle(size=60, color='orange').encode(
x='YearsExperience',
y='Salary'
)
Run to view results
scatter_chart
Run to view results
x = data['YearsExperience'].values
y = data['Salary'].values
Run to view results
# Solution
a = 0
b = 0
Run to view results
# Solution
y_hat = a * x + b
Run to view results
# Solution
preds = pd.DataFrame({'x': x, 'y': y_hat})
Run to view results
# solution
print(preds)
Run to view results
line_chart = alt.Chart(pd.DataFrame({'x': x, 'y': y_hat})).mark_line().encode(
x='x',
y='y'
)
Run to view results
scatter_chart + line_chart
Run to view results
# Solution
errors = y_hat - y
Run to view results
# Solution
errors
Run to view results
sum_error = errors.sum()
sum_error
Run to view results
def check_parameters(a, b, x, y):
y_hat = a * x + b
source = pd.DataFrame({'x': x, 'y': y})
preds = pd.DataFrame({'x': x, 'y': y_hat})
scatter_chart = alt.Chart(source).mark_circle(size=60, color='orange').encode(
x='x',
y='y'
)
line_chart = alt.Chart(preds).mark_line().encode(
x='x',
y='y'
)
errors = y_hat - y
sum_error = errors.sum()
print(sum_error)
return scatter_chart + line_chart
Run to view results
# Solution
check_parameters(a=100, b=0, x=x, y=y)
Run to view results
# Solution
check_parameters(a=5000, b=0, x=x, y=y)
Run to view results
# Solution
check_parameters(a=10000, b=0, x=x, y=y)
Run to view results
# Solution
check_parameters(a=10000, b=10000, x=x, y=y)
Run to view results
# Solution
check_parameters(a=10000, b=20000, x=x, y=y)
Run to view results
# Solution
check_parameters(a=10000, b=25000, x=x, y=y)
Run to view results
# Solution
check_parameters(a=9500, b=25000, x=x, y=y)
Run to view results
# Solution
check_parameters(a=9450, b=25800, x=x, y=y)
Run to view results