calories

Java构造器与构建器的使用

倾然丶 夕夏残阳落幕 提交于 2020-02-26 09:11:27
我们在平常类的构建过程中,可能会面临很多问题,可扩张性、安全性等等。想象一下,这样一个场景,我们现在要创建一个类,其中有6个属性,其中又有4个属性的值是不太确定的(可能某个对象就不需要其中的某个值),这时我们怎么创建这个类呢?以下是几种方法: 使用普通构造器 1 public class Test { 2 private int servingSize; 3 private int servings; 4 private int calories; 5 private int fat; 6 private int sodium; 7 private int carbohydrate; 8 9 public Test(int servingSize, int servings) { 10 this.servingSize = servingSize; 11 this.servings = servings; 12 this.calories = 0; 13 } 14 15 public Test(int servingSize, int servings, int calories) { 16 this.servingSize = servingSize; 17 this.servings = servings; 18 this.calories = calories; 19

Stream Reducing

拈花ヽ惹草 提交于 2020-02-24 05:07:43
Dish public class Dish { public Dish ( String name , boolean vegetarian , int calories , Type type ) { this . name = name ; this . vegetarian = vegetarian ; this . calories = calories ; this . type = type ; } public String getName ( ) { return name ; } public int getCalories ( ) { return calories ; } public boolean isVegetarian ( ) { return vegetarian ; } public Type getType ( ) { return type ; } private final String name ; private final boolean vegetarian ; private final int calories ; private final Type type ; public enum Type { MEAT , FISH , OTHER } Initializing Data private static List <

各种聚类算法的使用对比

谁说胖子不能爱 提交于 2020-02-07 02:34:46
1. 导入数据 # beer dataset import pandas as pd beer = pd . read_csv ( 'data.txt' , sep = ' ' ) beer 2.构建标签 X = beer [ [ "calories" , "sodium" , "alcohol" , "cost" ] ] 3.使用聚类算法 K-means clustering: from sklearn . cluster import KMeans km = KMeans ( n_clusters = 3 ) . fit ( X ) km2 = KMeans ( n_clusters = 2 ) . fit ( X ) km . labels_ beer [ 'cluster' ] = km . labels_ beer [ 'cluster2' ] = km2 . labels_ beer . sort_values ( 'cluster' ) from pandas . plotting import scatter_matrix % matplotlib inline cluster_centers = km . cluster_centers_ cluster_centers_2 = km2 . cluster_centers_ beer . groupby (

error: incompatible types: possible lossy conversion from double to int

匿名 (未验证) 提交于 2019-12-03 01:44:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: public class FoodItem { private String name; private int calories; private int fatGrams; private int caloriesFromFat; public FoodItem(String n, int cal, int fat) { name = n; calories = cal; fatGrams = fat; } public void setName(String n) { name = n; } public void setCalories(int cal) { calories = cal; } public void setFatGrams(int fat) { fatGrams = fat; } public String getName() { return name; } public int getCalories() { return calories; } public int getFatGrams() { return fatGrams; } public int getCaloriesFromFat() { return (fatGrams * 9.0

Mysql: Swap data for different rows

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Suppose a table fruits that looks like this: ------------------------------------------ | id | name | color | calories | ------------------------------------------ | 1 | apple | red | 20 | | 2 | orange | orange | 10 | | 3 | grapes | green | 5 | | 4 | bananas | yellow | 15 | | 5 | plum | purple | 25 | ------------------------------------------ How can I swap the values of a row, with another, leaving the id number intact? Example: SWAP ROW WITH ID "5" WITH ROW WITH ID "2" Result: ------------------------------------------ | id | name | color

聚类

安稳与你 提交于 2019-11-28 05:32:26
kmeans是一种无监督的聚类问题,在使用前一般要进行数据标准化, 一般都是使用欧式距离来进行区分,主要是通过迭代质心的位置 来进行分类,直到数据点不发生类别变化就停止, 一次分类别,一次变换质心,就这样不断的迭代下去 优势:使用方便 劣势:1.K值难确定 2. 复杂度与样本数量呈线性关系 3.很难发现形状任意的簇 4.容易受初始点的影响 python中使用 sklearn.cluster 模块,使用的时候需要指定参数 第一步:导入数据,提取数据中的变量保存为X import pandas as pd beer = pd.read_csv('data.txt', sep=' ') X = beer[["calories","sodium","alcohol","cost"]] 第二步:进行kmans聚类分析 from sklearn.cluster import KMeans km = KMeans(n_clusters=3).fit(X) #聚成三蔟 km2 = KMeans(n_clusters=2).fit(X) #聚成两蔟 beer['cluster'] = km.labels_ #返回聚类的标签结果 beer['cluster2'] = km2.labels_ beer.sort_values('cluster') #根据'cluster'进行排序 第三步