[Python] why x_test and x_train are equal [closed]

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    The code should split dataset 'x' into distinct training (x_train) and testing (x_test) subsets, but currently fails to do

    code must split the x to x_train and x_test but my code don't work,why x_train and x_test are equal and same?

    stop_words = stopwords.words("english")
    neg = []
    for file in os.listdir("dataset/neg"):
    with open("dataset/neg/" + file) as f:
    text = f.read()
    tokens = word_tokenize(text)
    translator = str.maketrans("", "", punctuation)
    clean_tokens = []
    for w in tokens:
    word = w.translate(translator)
    if word.lower() not in stop_words:
    clean_tokens.append(word)
    tokens = clean_tokens
    neg.append(" ".join(tokens))

    pos = []
    for file in os.listdir("dataset/pos"):
    with open("dataset/pos/" + file) as f:
    text = f.read()
    tokens = word_tokenize(text)
    translator = str.maketrans("", "", punctuation)
    clean_tokens = []
    for w in tokens:
    word = w.translate(translator)
    if word.lower() not in stop_words:
    clean_tokens.append(word)
    tokens = clean_tokens
    pos.append(" ".join(tokens))

    x = np.concatenate([neg,pos])
    y_neg =[]
    for nege in range(0,700):
    y_neg.append(0)

    y_pos =[]
    for pose in range(0,700):
    y_neg.append(1)

    y = np.concatenate([y_neg,y_pos])


    x_train,y_train,x_test,y_test = train_test_split(x,y,test_size=0.2)

    print(len(x_train))
    print(len(x_test))

    Continue reading...

Compartilhe esta Página