以下是实现任务的代码,包括成本增加额和新增任务完成量的计算: ```python # -*- coding: utf-8 -*- # 对未完成的任务重新定价效果进行评估 import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.svm import SVC # 加载数据 A = pd.read_excel('附件一:已结束项目任务数据.xls') Z = np.load('Z.npy') # 数据预处理 xx = Z[:, :-1] # 自变量 yy = Z[:, -1].reshape(len(Z), 1) # 因变量 # 划分训练集和测试集 xx_train, xx_test, yy_train, yy_test = train_test_split(xx, yy, test_size=0.2, random_state=4) # 构建支持向量机模型 clf = SVC(kernel='rbf', class_weight='balanced') clf.fit(xx_train, yy_train.ravel()) # 训练模型 # 模型准确率 model_accuracy = clf.score(xx_train, yy_train) print('模型准确率:', model_accuracy) # 预测测试集 yy_pred = clf.predict(xx_test).reshape(-1, 1) prediction_accuracy = np.mean(yy_pred == yy_test) print('预测准确率:', prediction_accuracy) # 新增任务完成量计算 P = clf.predict(xx) # 全量数据预测 num_executed_tasks = len(P[P == 1]) # 模型输出为1的数量 task_completion_increase = int(num_executed_tasks * prediction_accuracy) # 新增任务完成量 print('新增任务完成量:', task_completion_increase) # 成本增加额计算 original_prices = A['原定价'].values # 原定价 new_prices = A['新定价'].values # 新定价 cost_increase = np.sum(new_prices) - np.sum(original_prices) # 成本增加额 print('成本增加额:', cost_increase) # 返回结果 def return_values(): R1 = cost_increase R2 = task_completion_increase return R1, R2 R1, R2 = return_values() print('最终结果:成本增加额=', R1, '新增任务完成量=', R2) ``` 需要注意的逻辑点 1. 确保输入数据中没有缺失值或异常值,否则可能影响模型训练和预测结果。 2. 在计算新增任务完成量时,模型的预测准确率至关重要,需要确保模型具有足够的泛化能力。 3. 成本增加额的计算依赖于新定价和原定价的数据完整性,需确认两列数据无误。 [2025-05-04 22:36:52 | AI写代码神器 | 578点数解答]