How to Find Gender with Height and Weight from a Data Set Using Logistic Regression in Weka?
Share
Condition for Finding Gender with Height and Weight using Logistic Regression in Weka
Description: To use logistic regression in Weka for gender prediction, first load the dataset (e.g., height, weight, gender) and set the target variable (gender) as the class attribute. Then, create and train a logistic regression model using the Logistic classifier. Finally, make predictions by inputting new data (height and weight) and output the predicted gender based on the trained model.
public class LogisticRegression {
public static void main(String[] args) {
try {
DataSource source = new DataSource("/home/soft20/NetBeansProjects/JavaSamples/gender_height_weight.arff"); // Ensure this path is correct
Instances dataset = source.getDataSet();
if (dataset.classIndex() == -1) {
dataset.setClassIndex(dataset.numAttributes() - 1);
}
Classifier logistic = new Logistic();
logistic.buildClassifier(dataset);