小编Vis*_*kar的帖子

Scikit-learn:拟合模型中的错误 - 输入包含NaN,无穷大或者对于float64来说太大的值

我正在使用Python scikit-learn对从csv获得的数据进行简单的线性回归.

reader = pandas.io.parsers.read_csv("data/all-stocks-cleaned.csv")
stock = np.array(reader)

openingPrice = stock[:, 1]
closingPrice = stock[:, 5]

print((np.min(openingPrice)))
print((np.min(closingPrice)))
print((np.max(openingPrice)))
print((np.max(closingPrice)))

peningPriceTrain, openingPriceTest, closingPriceTrain, closingPriceTest = \
    train_test_split(openingPrice, closingPrice, test_size=0.25, random_state=42)


openingPriceTrain = np.reshape(openingPriceTrain,(openingPriceTrain.size,1))

openingPriceTrain = openingPriceTrain.astype(np.float64, copy=False)
# openingPriceTrain = np.arange(openingPriceTrain, dtype=np.float64)

closingPriceTrain = np.reshape(closingPriceTrain,(closingPriceTrain.size,1))
closingPriceTrain = closingPriceTrain.astype(np.float64, copy=False)

openingPriceTest = np.reshape(openingPriceTest,(openingPriceTest.size,1))
closingPriceTest = np.reshape(closingPriceTest,(closingPriceTest.size,1))

regression = linear_model.LinearRegression()

regression.fit(openingPriceTrain, closingPriceTrain)

predicted = regression.predict(openingPriceTest)
Run Code Online (Sandbox Code Playgroud)

最小值和最大值显示为0.0 0.6 41998.0 2593.9

然而,我收到此错误ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

我该如何删除此错误?因为从上面的结果来看,它确实不包含无限或纳米值. …

python numpy machine-learning scikit-learn

12
推荐指数
1
解决办法
4万
查看次数

Angular Material:如何在输入中添加逗号分隔的字符串时添加多个芯片?

我正在使用这种语法来创建芯片 -

<md-chips ng-model="someModel" md-separator-keys="seperatorKeys">
                            <md-chip-template >
                                <span>{{$chip}}</span>
                            </md-chip-template>
                        </md-chips>
Run Code Online (Sandbox Code Playgroud)

这是控制器代码的一部分.

$scope.seperatorKeys = [$mdConstant.KEY_CODE.ENTER, $mdConstant.KEY_CODE.COMMA];
Run Code Online (Sandbox Code Playgroud)

现在我想创建多个芯片,如果我在输入中粘贴逗号分隔字符串来添加芯片,让我们说,例如,如果我输入1234,5678作为输入,它应该创建1234为第一个芯片和5678第二个芯片.

我该如何实现此功能?

angularjs material-design angular-material

10
推荐指数
1
解决办法
2744
查看次数

控制器功能未在ng-click上调用

这是我的查看代码

<div ng-controller="signupCtrl">
<ul class="list-group" >
    <li class="list-group-item">
        <div class="form-group">
            <input type="text" ng-model="signupCtrl.firstName">
        </div>
    ...
        </div>


        <div class="form-group">
            <div class="pull-right">
                <button ng-click="signupCtrl.signupUser()">Register</button>
            </div>
        </div>
    </li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)

更新 - 这是我的控制器代码##

someAppControllers.controller('signupCtrl', [
    '$window', 
    '$scope',     
    'HttpReqHandlerService',     
    '$location', 
    'localStorageService'],
    function($window, $scope, HttpReqHandlerService, 
             $location, localStorageService) { 
        $scope.signupUser=function signupUser() {
        alert("hello");
    }]);
Run Code Online (Sandbox Code Playgroud)

该按钮未在我的控制器中调用signupUser功能

javascript jquery angularjs

6
推荐指数
1
解决办法
2万
查看次数

如何为选择列表的自定义指令实现ng-change?

我的指令用法代码

       <input-select ng-model="someModel" ng-change="someFunction()"
   options="countries"></input-select>
Run Code Online (Sandbox Code Playgroud)

我的指令代码

 .directive('inputSelect', function () {
    return {
        templateUrl: 'someTemplate.html',
        restrict: 'E',
        scope: {
            ngModel: '=',
            ngChange: '='
        }
    };
});
Run Code Online (Sandbox Code Playgroud)

我的指令模板

    <select 
            ng-model="ngModel" ng-init="ngModel "
            ng-options="option[optionId] as option[optionName] for option in options"
            ng-change="ngChange">
    </select>
Run Code Online (Sandbox Code Playgroud)

因此,当所选项被更改时,函数someFunction()将被无限次调用(尽管更改已完成一次),应该更改的内容以确保someFunction()只调用一次(someFunction()是控制器范围内的函数)该指令正在使用中)

[我确实尝试使用&和使用@ngChange的范围类型,somefunction()如果使用它们不会被解雇.]

javascript angularjs angularjs-directive angularjs-scope ng-options

6
推荐指数
1
解决办法
5750
查看次数

AngularJS:如何在服务中完成AJAX调用后执行控制器功能?

这是我在服务中的代码.

this.loginUser = function(checkUser) {
    Parse.User.logIn(checkUser.username, checkUser.password, {
        success: function(user) {
            $rootScope.$apply(function (){
                $rootScope.currentUser = user;
            });
        }
    });
};
Run Code Online (Sandbox Code Playgroud)

这是我在控制器中的代码:

$scope.logIn = function(){
    authenticationService.loginUser($scope.checkUser);
        console.log($scope.currentUser)
};
Run Code Online (Sandbox Code Playgroud)

所以,我想要做的是,在完成AJAX调用后执行一些代码,其成功函数设置$ scope.currentUser的值,我可以用于某些条件逻辑(如重定向等)成功函数是否正确设置值,但console.log应该在执行authenticationService.loginUser()功能后执行.

javascript ajax jquery xmlhttprequest angularjs

5
推荐指数
1
解决办法
1万
查看次数

Chrome应用:如何在后台将blob内容保存到fileSystem?

在Chrome应用中,我使用JavaScript XHR从服务器下载blob内容(特别是Angular $ http GET,响应类型为'blob')

我该如何将其保存到chrome应用程序的文件系统?

目前在HTML5文件系统API上使用Angular包装器 https://github.com/maciel310/angular-filesystem

我不想向用户显示弹出窗口(因此我无法使用chrome.fileSystem. chooseEntry)

chrome.fileSystem.requestFileSystemAPI仅受Kiosk专用应用程序支持.因此我使用的是HTML5 FileSystem API而不是chrome.

我正在使用以下代码来使XHR获取blob.

 $http({
          url: SERVER_URL+"/someVideo.mp4",
          method: "GET",
          responseType: "blob"
      }).then(function(response) {
          console.log(response);
          fileSystem.writeBlob(response.name, response).then(function() {
             console.log("file saved");
          }, function(err) {
              console.log(err);
          });
      }, function (response) {

      });
Run Code Online (Sandbox Code Playgroud)

这是我的writeBlob方法

writeBlob: function(fileName, blob, append) {
    append = (typeof append == 'undefined' ? false : append);

    var def = $q.defer();

    fsDefer.promise.then(function(fs) {

        fs.root.getFile(fileName, {create: true}, function(fileEntry) {

            fileEntry.createWriter(function(fileWriter) {
                if(append) {
                    fileWriter.seek(fileWriter.length);
                }

                var truncated = false; …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome angularjs html5-filesystem google-chrome-app

5
推荐指数
1
解决办法
2422
查看次数

Thymeleaf:如何在没有迭代的情况下获得列表的第一个元素?

foo.messageData是一个清单.messageData包含name为字符串.

在thymeleaf html模板中,我想打印name第一个元素的属性值messageData.

像这样的东西foo.messageData[0].name:

<span th:text="foo.messageData[0].name"></span>
Run Code Online (Sandbox Code Playgroud)

<span th:text="foo.messageData.get(0).name"></span>
Run Code Online (Sandbox Code Playgroud)

不管用.

如何打印这些数据?在Thymeleaf中有没有特定的语法?

我知道这个值可以通过迭代使用来打印th:each; 但我不想要这些迭代.

html spring html-email thymeleaf

5
推荐指数
2
解决办法
1万
查看次数

如何将反应组件作为变量传递给子组件?

当我在一个变量中定义了一个组件,并且我试图将它作为子道具传递给一个组件时,Objects are not valid as a React child会显示错误。

这样做的正确方法是什么?

function AnotherComponent(){
  return "Another";
}

function ChildComponent(props) {
  const { children, value, index, ...other } = props;

  console.log(children);
  return (
    <Typography
      component="div"
      role="tabpanel"
      hidden={value !== index}
      id={`full-width-tabpanel-${index}`}
      aria-labelledby={`full-width-tab-${index}`}
      {...other}
    >
      <Box p={3}>{children}</Box>
    </Typography>
  );
}

function MainComponent(){
  const tabItems = [
    { "component": AnotherComponent}
  ];

  const [value, setValue] = React.useState(0);

  return (
    <>
      {tabItems.map((tabItem,index) => (
        <ChildComponent value={value} index={tabItem.index}>
          {tabItem.component}
        </ChildComponent>
      ))}
    </>
  )
}
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui react-hooks

3
推荐指数
1
解决办法
2237
查看次数