import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
data = {
'experience': [0, 0, 5, 2, 7, 3, 10, 11],
'test_score': [8, 8, 6, 10, 9, 7, 0, 7],
'interview_score': [9, 6, 7, 10, 6, 10, 7, 8],
'salary': [50000, 45000, 60000, 65000, 70000, 62000,
72000, 80000]
}
# Create dataframe
df = pd.DataFrame(data)
print("Original Dataset:\n")
print(df)
# it is Features and target
X = df[['experience', 'test_score', 'interview_score']]
y = df['salary']
# Train Linear Regression model
model = LinearRegression()
model.fit(X, y)
# Predict salaries for new candidates
candidates = np.array([[2, 9, 6], [12, 10, 10]]) #
(experience, test_score, interview_score)
predicted_salaries = model.predict(candidates)
# Create results table
results = pd.DataFrame({
"Candidate": ["2 yr exp, 9 test, 6 interview",
"12 yr exp, 10 test, 10 interview"],
"Predicted Salary": [round(s, 2) for s in
predicted_salaries]
})
print("\nPredicted Salaries:\n")
print(results)
Output:
Candidate 1 expected salary: 52688.25
Candidate 2 expected salary: 92940.63