GithubHelp home page GithubHelp logo

kaitumisuuringute-keskus / weightipy Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 63.61 MB

RIM iterative raking algorithm for people data

License: MIT License

Python 99.92% Shell 0.08%
raking weighting rim survey people data iterative iterake weights python

weightipy's People

Contributors

alasdaire avatar alexbuchhammer avatar alextanski avatar andersfreund avatar biggihs avatar braffolk avatar directions-dev avatar g3org3mb avatar geirfreysson avatar jamesrkg avatar majeed-sahebzadha avatar nitsrek avatar pablincho avatar roxanamarianeagu avatar roxananeagu avatar tokensalad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

weightipy's Issues

Error

I'm trying to weight a datset using the following code:

import weightipy as wp

Targets

gender_targets = {'Q2':{1:49, 2:51}}
region_targets = {'Q4':{1:32, 2:23, 3:10, 4:14, 5:21}}
scheme = wp.Rim('gender_and_age')
scheme.set_targets(targets=[gender_targets, region_targets])

df["respid"] = range(len(df))
engine = wp.WeightEngine(data=df)
engine.add_scheme(scheme=scheme, key="respid", verbose=False)
engine.run()
df_weighted = engine.dataframe()
col_weights = f"weights_{scheme.name}"

respid, Q2, Q3 and Q4 are integer columns.

I get a long error message beginning with:

FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas.

Further down after a series of floating point numbers the error states:

has dtype incompatible with int64, please explicitly cast to a compatible dtype first.

KeyError

Hi, I used Weightipy to cpmpute my data's weight,the code in below:

`age_targets = {'agecat':{1: 0.067468889, 2: 0.080224503, 3: 0.081368672, 4: 0.084373472, 5: 0.102660891
,6:0.094806186,7:0.090030135,8:0.090639452,9:0.088830485,10:0.077339418,11:0.136466392,98:0.005791506}}

gender_targets = {'gender':{1: 0.488588237, 2: 0.511411763}}

county_targets = {"county":{2:0.019395905,4:0.023782735,5:0.02292341,7:0.02292341,8:0.02088535,9:0.028729086,10:0.021700082
,13:0.034964756,14:0.009158398,15:0.013730506,16:0.004724007,17:0.015997925,18:0.018345312,20:0.011139324
,63:0.107256094,64:0.11836086,65:0.173914542,66:0.118862683,67:0.080211099,68:0.095929136,72:0.006447622}}

scheme = wp.Rim('gender_and_age_and_county')
scheme.set_targets(targets=[age_targets, gender_targets,county_targets])

pres_df["identity"] = range(len(pres_df))
engine = wp.WeightEngine(data=pres_df)
engine.add_scheme(scheme=scheme, key="identity", verbose=False)
engine.run()
df_weighted = engine.dataframe()
col_weights = f"weights_{scheme.name}"

efficiency = wp.weighting_efficiency(df_weighted[col_weights])
`
when run this code,show KeyError: "['gender', 'agecat', 'county'] not in index",how do I to fix it? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.