CoolFace
Apppublic

Soly663/Genetic_Algorithm-choosingFeature

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
baseline-model.py48 linesDownload Raw Back to root
1import pandas as pd2from sklearn.datasets import load_breast_cancer3from sklearn.model_selection import train_test_split4from sklearn.linear_model import LogisticRegression5from sklearn.metrics import accuracy_score6 7 8"""9A baseline model using Logistic Regression on the breast cancer dataset.10This is a testing file to ensure the environment is set up correctly.11"""12def main():13    # 1. Load Data14    cancer = load_breast_cancer()15    X = pd.DataFrame(cancer.data, columns=cancer.feature_names)16    y = pd.Series(cancer.target)17 18    print("Dataset loaded.")19    print(f"Number of features: {X.shape[1]}")20    print("Feature names:")21    print(list(X.columns))22    print("-" * 30)23 24    # 2. For now, let's manually select the FIRST 10 features as an example25    # This is what a 'chromosome' will do automatically later26    selected_features = X.columns[:10]27    X_subset = X[selected_features]28    29    print(f"Using a subset of {len(selected_features)} features.")30 31    # 3. Split data for training and testing32    X_train, X_test, y_train, y_test = train_test_split(33        X_subset, y, test_size=0.3, random_state=4234    )35    36    # 4. Train a simple model37    model = LogisticRegression(max_iter=10000) # max_iter to ensure convergence38    model.fit(X_train, y_train)39    print("Model trained.")40    41    # 5. Evaluate the model42    predictions = model.predict(X_test)43    accuracy = accuracy_score(y_test, predictions)44 45    print(f"Model accuracy with the first {len(selected_features)} features: {accuracy:.4f}")46 47if __name__ == "__main__":48    main()