如何对数据进行分区,然后对其中的一部分进行建模(例如验证)以进行名义逻辑回归?
JMP Pro绝对让这一点毫不费力,但这里有一种模仿JMP Pro创建分区功能的方法。 使用分区仍然是非常手动的。 您可以隐藏/排除val和测试集以使模型适合训练数据,然后使用从您使用的任何平台保存的预测公式,使用val和测试集上的训练模型进行预测。
dt = Current Data Table();
n_rows = N Row(dt);
//determine proportions for training and validation sets (test is whatever is left over)
train_prop = 0.7;
val_prop = 0.15;
test_prop = 1-train_prop-val_prop;
//randomly shuffle row numbers
rows_shuffled = random shuffle(1::n_rows);
//determine precise number of data points for each partition
n_train = floor(train_prop*n_rows);
n_val = ceiling(val_prop*n_rows);
n_test = n_rows - n_train - n_val;
//obtain the desired data points for the partitions
train_rows = rows_shuffled[1::n_train];
val_rows = rows_shuffled[(n_train+1)::(n_train+1+n_val)];
test_rows = rows_shuffled[(n_rows-n_test)::n_rows];
//Create the partition column
partition_col = dt << New Column("Partition", numeric, nominal); //use partition_col just in case a Partition column already exists and the new column gets a name like "Partition 2"
//mimic JMP Prop underlying numeric values
partition_col[train_rows] = 1;
partition_col[val_rows] = 2;
partition_col[test_rows] = 3;
//Add value labels
partition_col << Add Column Properties({Value Labels( {"." = "Other", 1 = "Training", 2 = "Validation", 3 = "Test"} ),
Use Value Labels( 1 )});我只是把它一起鞭打了,但你可以轻松地将它变成一个带有对话框的应用程序,询问培训和验证的比例。 您可以通过“视图”>“自定义”>“菜单”和“工具栏”将该应用程序的脚本添加到菜单或工具栏中,从而使其变得非常方便。
阻力最小的路径是使用JMP Pro和Make Validation Column实用程序。考虑可能使用分层随机选项来分区响应变量集。然后,当您实际启动平台时,请确保将列名放在Fit Model平台启动窗口的Validation窗口中。