'ValueError: X has 4 features, but StandardScaler is expecting 1 features as input

symbol = 'BTCUSDT'  #symbol  
quantity = '0.05'   #quantity to trade   
  
  
order = False  
index = [496,497,498,499]
  
while True:  
    price = client.get_recent_trades(symbol= symbol)
    candle = client.get_klines(symbol=symbol, interval=Client.KLINE_INTERVAL_1MINUTE)
    candles = scaler.transform(np.array([float(candle[i][4]) for i in index]).reshape(1,-1))
    model_feed = candles.reshape(1,4,1)
    
  
    if order == False and float(price[len(price)-1]['price']) < float(scaler.inverse_transform(model.predict(model_feed)[0])[0]):    
          
        #client.order_market_buy(symbol= symbol, quantity= quantity)                            
        order = True                                                                            
        buy_price = client.get_order_book(symbol=symbol)['asks'][0][0]                          
        print('Buy @Market Price :',float(buy_price),' Timestamp :',str(datetime.now()))        
  
    elif order == True and float(price[len(price)-1]['price'])-float(buy_price) >= 10:            
          
        #client.order_market_sell(symbol= symbol , quantity= quantity)                         #fires sell order to exhcange if conditionality satisfies  
        order = False                                                                          #sets order = False and closes open position  
        sell_price = client.get_order_book(symbol=symbol)['bids'][0][0]                        #gets the highest bid for the market order   
        print('Sell @Market Price :',float(sell_price),' Timestamp :',str(datetime.now()))     #print sell price and datetime   
  
    else:  
        pass  

Traceback (most recent call last):

  File "C:\Users\info\.spyder-py3\untitled0.py", line 233, in <module>
    candles = scaler.transform(np.array([float(candle[i][4]) for i in index]).reshape(1,-1))

  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\_data.py", line 883, in transform
    X = self._validate_data(X, reset=False,

  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 437, in _validate_data
    self._check_n_features(X, reset=reset)
  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn\base.py", line 365, in _check_n_features
    raise ValueError(

ValueError: X has 4 features, but StandardScaler is expecting 1 features as input.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source