0% found this document useful (0 votes)
4 views2 pages

Assignment File

The document outlines a Python script that uses linear regression to predict salaries based on candidates' experience, test scores, and interview scores. A dataset is created with various candidates' attributes, and a model is trained to make salary predictions for two new candidates. The predicted salaries are displayed in a results table, showing expected salaries of approximately 52688.25 for the first candidate and 92940.63 for the second.

Uploaded by

andrewbrhmx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Assignment File

The document outlines a Python script that uses linear regression to predict salaries based on candidates' experience, test scores, and interview scores. A dataset is created with various candidates' attributes, and a model is trained to make salary predictions for two new candidates. The predicted salaries are displayed in a results table, showing expected salaries of approximately 52688.25 for the first candidate and 92940.63 for the second.

Uploaded by

andrewbrhmx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like