اذهب إلى المحتوى

Meezo ML

الأعضاء
  • المساهمات

    197
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة Meezo ML

  1. أحاول بناء نموذج  باستخدام خوارزمية  LogisticRegression  لكن أواجه الخطأ التالي:

    import numpy as np
    from sklearn.linear_model           
    import LogisticRegression
    X_train   = np.array([ [2.3, 4.3, 2.5],  [1.3, 5.2, 5.2],  [3.3, 2.9, 0.8],  [3.1, 4.3, 4.0]  ])
    y_train  = np.array( [3.4, 7.5, 4.5, 1.6] )
    X_test  = np.array([ [2.5, 2.4, 2.7],  [2.7, 3.2, 1.2] ])
    LR = LogisticRegression()
    LR.fit(X_train,y_train)
    print(clf.predict(X_test))
    ##################################
    ValueError                                Traceback (most recent call last)
    <ipython-input-23-8aa4b13afdb8> in <module>
          7 
          8 LR = LogisticRegression()
    ----> 9 LR.fit(X_train,y_train)
         10 print(clf.predict(X_test))
         11 
    
    ~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
       1526         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
       1527                          accept_large_sparse=solver != 'liblinear')
    -> 1528         check_classification_targets(y)
       1529         self.classes_ = np.unique(y)
       1530         n_samples, n_features = X.shape
    
    ~\anaconda3\lib\site-packages\sklearn\utils\multiclass.py in check_classification_targets(y)
        167     if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
        168                       'multilabel-indicator', 'multilabel-sequences']:
    --> 169         raise ValueError("Unknown label type: %r" % y_type)
        170 
        171 
    
    ValueError: Unknown label type: 'continuous'

     

  2. أعمل على مجموعة بيانات "داتاسيت" هي تغريدات تويتر، لذا  قمت مبدأياً ببناء نموذج LogisticRegrission  لكن لاأعلم سبب الخطأ التالي:

    <class 'pandas.core.series.Series'>
    
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-9-20b55637dec5> in <module>
         10 print(type(X_train))
         11 clf = LogisticRegression()
    ---> 12 clf.fit(X_train, y_train)
    
    ~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
       1525 
       1526         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
    -> 1527                          accept_large_sparse=solver != 'liblinear')
       1528         check_classification_targets(y)
       1529         self.classes_ = np.unique(y)
    
    ~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
        753                     ensure_min_features=ensure_min_features,
        754                     warn_on_dtype=warn_on_dtype,
    --> 755                     estimator=estimator)
        756     if multi_output:
        757         y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,
    
    ~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
        529                     array = array.astype(dtype, casting="unsafe", copy=False)
        530                 else:
    --> 531                     array = np.asarray(array, order=order, dtype=dtype)
        532             except ComplexWarning:
        533                 raise ValueError("Complex data not supported\n"
    
    ~\anaconda3\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
         81 
         82     """
    ---> 83     return array(a, dtype, copy=False, order=order)
         84 
         85 
    
    ~\anaconda3\lib\site-packages\pandas\core\series.py in __array__(self, dtype)
        752               dtype='datetime64[ns]')
        753         """
    --> 754         return np.asarray(self.array, dtype)
        755 
        756     # ----------------------------------------------------------------------
    
    ~\anaconda3\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
         81 
         82     """
    ---> 83     return array(a, dtype, copy=False, order=order)
         84 
         85 
    
    ~\anaconda3\lib\site-packages\pandas\core\arrays\numpy_.py in __array__(self, dtype)
        182 
        183     def __array__(self, dtype=None) -> np.ndarray:
    --> 184         return np.asarray(self._ndarray, dtype=dtype)
        185 
        186     _HANDLED_TYPES = (np.ndarray, numbers.Number)
    
    ~\anaconda3\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order)
         81 
         82     """
    ---> 83     return array(a, dtype, copy=False, order=order)
         84 
         85 
    
    ValueError: could not convert string to float: 'قزم العهد'
    

    الكود:

    from sklearn.linear_model import LogisticRegression
    from sklearn.model_selection import train_test_split
    import pandas as pd
    Data = pd.read_csv('D:/train.csv')
    Data['Tweet'] =Data['Tweet'].astype(str)  
    data["Class"].replace({"abusive":0,"hate":0,"normal":1},inplace=True) 
    data = Data['Tweet']
    label = Data["Class"]
    X_train, X_test, y_train, y_test = train_test_split(data, label, test_size = 0.2, random_state = 2021)
    clf = LogisticRegression()
    clf.fit(X_train, y_train)

     

  3. في مكتبة sklearn حاولت استخدام Gaussian Naive Bayes Module:

    training = GaussianNB()
    training = training.fit(trainData, target)
    prediction = training.predict(testData)

    والبيانات كانت:

    [['-214' '-153' '-58' ..., '36' '191' '-37']
    ['-139' '-73' '-1' ..., '11' '76' '-14']
    ['-76' '-49' '-307' ..., '41' '228' '-41']
    ..., 
    ['-32' '-49' '49' ..., '-26' '133' '-32']
    ['-124' '-79' '-37' ..., '39' '298' '-3']
    ['-135' '-186' '-70' ..., '-12' '790' '-10']]

    ظهر لدي الخطأ التالي :

    Traceback (most recent call last):
    File "prediction.py", line 90, in <module>
      gaussianNaiveBayes()
    File "prediction.py", line 76, in gaussianNaiveBayes
      training = training.fit(trainData, target)
    File "/Library/Python/2.7/site-packages/sklearn/naive_bayes.py", line 163, in fit
      self.theta_[i, :] = np.mean(Xi, axis=0)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/ core/fromnumeric.py", line 2716, in mean
      out=out, keepdims=keepdims)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/_methods.py", line 62, in _mean
      ret = um.add.reduce(arr, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
    TypeError: cannot perform reduce with flexible type

    ما المشكلة؟

  4. أحاول تطبيق التوقع الخطي LinearRegression في مكتبة Sklearn كالتالي:

    reg = LinearRegression(max_iter=1000,verbose=0)
    reg.fit(df.iloc[1:1000, 5].values, df.iloc[1:1000, 2].values)

    لكن يظهر لي الخطأ:

    ValueError: Found arrays with inconsistent numbers of samples: [  1 999]

     

  5. ماسبب هذا الخطأ في بايثون عندما أقوم باستخدام الدالة .fit_generator من تنسرفلو

    /usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/training.py:1940: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.

     

×
×
  • أضف...