Commit dfec8f72 authored by Zhangkai Wu's avatar Zhangkai Wu
Browse files

删除template_assignment_8_2_pytorch.ipynb

parent d6caac36
Loading
Loading
Loading
Loading
+0 −64
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
# You are encouraged to follow this template as a guide, but feel free to make reasonable modifications as needed.
# The key requirement is that your code runs successfully and produces the expected results.
```

%% Cell type:code id: tags:

``` python
# NOTE:
# You may choose to use ChatGPT (or any AI-based tool) to assist with your assignment,
# but you must ensure that you fully understand the entire code.
# You are solely responsible for the work you submit.
# Please keep in mind: ChatGPT will not be available during the exam.
```

%% Cell type:code id: tags:

``` python
import pandas
import torch
import torch.nn as nn
from sklearn.metrics import accuracy_score
from torch.autograd import Variable


class Model(nn.Module):
    def __init__(self, input_features, hidden_layer1, hidden_layer2, output_features):
        super().__init__()
        # TODO: Implement this function

    def forward(self, x):
        # TODO: Implement this function
        return 0


def preprocess_dataset(dataset):
    dataset = dataset.replace("?", -1)

    dataset.iloc[:, 0] = dataset.iloc[:, 0].astype("category")
    cat_columns = dataset.select_dtypes(["category"]).columns
    dataset[cat_columns] = dataset[cat_columns].apply(lambda x: x.cat.codes)

    dataset = dataset.astype("float64")

    X = dataset.iloc[:, 1:]
    y = dataset.iloc[:, 0]

    return X, y


if __name__ == "__main__":
    # Main function of script
    train = pandas.read_csv("/home/jovyan/data/IntroML/Chapter8_data/Assignment_1/soybean-large.data.csv", header=None)

    test = pandas.read_csv("/home/jovyan/data/IntroML/Chapter8_data/Assignment_1/soybean-large.test.csv", header=None)

    X_train, y_train = preprocess_dataset(train)

    X_test, y_test = preprocess_dataset(test)

    # TODO: Implement learning and prediction
```