Outputs you create
answer- The requested result, with the values, labels and row order described by this task.
case_id | backlog_at_open | device_age_years | completion_hours | invoice_hours |
|---|---|---|---|---|
| 4100 | 7 | 2.88157 | 9.42823 | 9.67823 |
| 4101 | 11 | 8.87485 | 17.2581 | 17.5081 |
| 4102 | 3 | 2.2896 | 7.74669 | 7.99669 |
| 4103 | 13 | 1.17218 | 14.7785 | 15.0285 |
| 4104 | 3 | 4.75178 | 5.76434 | 6.01434 |
| 4105 | 6 | 3.25684 | 8.09476 | 8.34476 |
| 4106 | 2 | 4.57092 | 4.09819 | 4.34819 |
| 4107 | 11 | 1.42743 | 11.8684 | 12.1184 |
Your task
- Retrieve two-feature polynomial expansion for the intake measurements in INTAKE48.
- Expand
backlog_at_openanddevice_age_yearsto degree two without a bias column. - Return
answeras a dataframe with all five fitted feature-name columns and the original row index. - Verify that the interaction column contains the product of the two available measurements.
answerHints
Think: Expanded terms represent available inputs; neither ID nor invoice belongs in the expansion.
Tools: PolynomialFeatures.fit_transform and get_feature_names_out.
Approach: Keep original observation indices and name each numerical term in fitted feature order.
Explained solution
from sklearn.preprocessing import PolynomialFeatures
expander = PolynomialFeatures(degree=2,include_bias=False)
values = expander.fit_transform(df[['backlog_at_open','device_age_years']])
answer = pd.DataFrame(values,index=df.index,columns=expander.get_feature_names_out())
The interaction term lets a coefficient’s effective contribution depend on the other input. Constructing that term does not establish a useful validation improvement.